Help with 3D contours aligned to discrete surface data
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Running the included code produces the included plot.
Basically a 3D plot of Z along a non-equi-spaced orthogonal mesh in x and y. It generates 3D contours, but they do not lie on the surface. Most are hidden on the reverse side.
Close inspection suggests they appear to lie on a 'smoothed' invisible surface offset from coloured surface. I'm obviously missing something, but if possible, i wish to have black contour lines aligned with the colour interpolated surface.
Data;
figure()
surf(pc,of,c,...
'LineStyle','-',...
'EdgeColor',[0.5 0.5 0.5],...
'FaceColor','interp')
zmin=min(c(:));
zmax=max(c(:));
xlabel 'P_c [bar]'
ylabel '(o/f)_m'
zlabel '{\rho} [kg/m^3]'
set(gca,'xscale','log','yscale','log')
hold on
number=20;
range=zmax-zmin;
inct=range/number;
contourl=zmin:inct:zmax;
contour3(pc,of,c,...
contourl,...
'k')
hold off
colormap (jet(256))
colorbar
채택된 답변
Star Strider
2022년 10월 11일
Reading the files is not an option, so I went straight for the ‘Problem.fig’ file.
I’m not certain that the contour lines aren’t plotting on the surface, however they appear to be the same colours as the surface, and that may be hiding them. One option is to make the surface slightly more transparent, and perhaps also to make the lines black (however the line colour does not appear to change) —
F = openfig(websave('Problem','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1152063/Problem.fig'));
getF = get(F);
Ax = findobj(F, 'Type','Axes');
getAx = get(Ax);
Kids = Ax.Children
Kids =
2×1 graphics array:
Contour
Surface
Kids(2).FaceAlpha = 0.75; % Necessary (Experiment With Different Values)
hc = Kids(1);
hc.LineWidth = 2; % Optional
hc.LineColor = 'k'; % Optional

I tried a few other experiments, however this is the only one that appears to work reliably.
.
댓글 수: 8
Had a play with your suggestions. My contour lines look grey from the 'front' where they appear behind the surface, and black where they appear to break through. Tried to include a side-view to show the discrepancy.
I could post a listing of code and data if it helps?
That, and any necessary data would definitely help.
I experimented with a few other options, such as slightly adjusting ‘hc.XData’ and ‘hcYData’ to position them in front of the surface.
However the solution could be to increase the resolution of the surface matrices, since the contours may be positioned more accurately than the surface is calculated, so the surface is ‘hiding’ them.
Brantosaurus
2022년 10월 11일
이동: Star Strider
2022년 10월 11일
pc=[1,2,5,10,20,30,70];
of=[.4,.5,.7,1,2,5,7,10,15,20,30,50,100];
c = ...
[0.0017674827252359125 0.0034928953583669106 0.0086195366120220048 0.017124176611165637 ...
0.034143398442433019 0.051218736178458645 0.12001289207216918;
0.0018068005529565489 0.003551383099562115 0.0086803360476427321 0.017076112299181902 ...
0.033618638796160928 0.049991490131899421 0.11475388176066162;
0.0019531349738764457 0.0039062699477528228 0.0097656748693817144 0.019531349738762884 ...
0.039062699477527184 0.058594049216288857 0.1333262758374037;
0.0017431832567206787 0.0034863666754282947 0.0087159170479174635 0.017431834458060094 ...
0.034863669428388061 0.052295504483000917 0.122022845014209;
0.0014131809499508014 0.0028267829949186253 0.00706791058386975 0.01413679607679336 ...
0.02827498281119966 0.042413403094375669 0.098967951293817455;
0.0011158017855461457 0.0022453178307318862 0.0056602634883156549 0.011389014741872509 ...
0.022904549726755753 0.03445853191114668 0.080840987037328324;
0.0011743831519246939 0.0023284213425193477 0.0057638931189663706 0.011459136917774138 ...
0.022816253547166786 0.0341614268453073 0.079555389365864385;
0.0014452051461961775 0.0028677243059421929 0.0071059195099525277 0.014134868528229745 ...
0.028149902485428785 0.042143489995637114 0.098064998893735253;
0.0019305793044475264 0.0038654804342955224 0.0096915251056551334 0.019439727316775662 ...
0.039007713832494059 0.058629460927678553 0.13738134183824333;
0.0025020721096050808 0.0050299267323266651 0.012654857267640634 0.02542067292452125 ...
0.0510435257542246 0.0767284149515598 0.17974873795853771;
0.0037672597528130487 0.0075526417223835659 0.018932356940629613 0.037929126577915619 ...
0.0759682952336209 0.11403727534491258 0.26644307816087959;
0.0062373784033877607 0.012477153937999945 0.031199269423554773 0.0624063106059884 ...
0.12482552364311707 0.18724804181050336 0.43695232360844904;
0.012153601056849095 0.02430720993001835 0.060768045848069011 0.12153610513709463 ...
0.24307227729500588 0.36460844797376918 0.85075317616518231];
figure()
surf(pc,of,c,...
'LineStyle','-',...
'EdgeColor',[0.5 0.5 0.5],...
'FaceColor','interp',...
'FaceAlpha', 0.75)
zmin=min(c(:));
zmax=max(c(:));
xlabel 'P_c [bar]'
ylabel '(o/f)_m'
zlabel '{\rho} [kg/m^3]'
set(gca,'xscale','log','yscale','log')
hold on
number=20;
range=zmax-zmin;
inct=range/number;
contourl=zmin:inct:zmax;
contour3(pc,of,c,...
contourl,...
'k')
hold off
colormap (jet(256))
colorbar
The data input is from an external computer program.
When you say increase the resolution of the surface matrices, i can make the program increase the sample intervals and range of [pc] and [of] vectors. [c] will increase in accordance with these. I would prefer to maintain liner interpolation between data points without cubic type smoothing.
Might meshgrid be something that might help in this respect?
A finer mesh might be the best approach, although I cannot understand the problems contour3 is having with it. I haven’t encountered this sort of problem with it before. (I couldn’t find an appropriate way to interpolate it because that would likely involve something other than linear interpolation — most likely 'pchip' — since a linear interpolation would not solve the problem. That would only create more linearly-interpolated areas in the surface, and the contour lines would still be behind them.)
The only thing I can think of is that contour3 is interpolating and the contours are ‘behind’ the surface for that reason. They do not exactly match it.
The only interim solution I can suggest is something like this —
contour3(pc*0.95,of*0.95,c,20,'k')
That ‘pulls’ the contours slightly to the front of the surface. It ‘sort of’ solves the problem, however there are compromises. (I had experimented with this approach with the figure file. It’s easier with the code.)
I implemented it here —
pc=[1,2,5,10,20,30,70];
of=[.4,.5,.7,1,2,5,7,10,15,20,30,50,100];
c = ...
[0.0017674827252359125 0.0034928953583669106 0.0086195366120220048 0.017124176611165637 ...
0.034143398442433019 0.051218736178458645 0.12001289207216918;
0.0018068005529565489 0.003551383099562115 0.0086803360476427321 0.017076112299181902 ...
0.033618638796160928 0.049991490131899421 0.11475388176066162;
0.0019531349738764457 0.0039062699477528228 0.0097656748693817144 0.019531349738762884 ...
0.039062699477527184 0.058594049216288857 0.1333262758374037;
0.0017431832567206787 0.0034863666754282947 0.0087159170479174635 0.017431834458060094 ...
0.034863669428388061 0.052295504483000917 0.122022845014209;
0.0014131809499508014 0.0028267829949186253 0.00706791058386975 0.01413679607679336 ...
0.02827498281119966 0.042413403094375669 0.098967951293817455;
0.0011158017855461457 0.0022453178307318862 0.0056602634883156549 0.011389014741872509 ...
0.022904549726755753 0.03445853191114668 0.080840987037328324;
0.0011743831519246939 0.0023284213425193477 0.0057638931189663706 0.011459136917774138 ...
0.022816253547166786 0.0341614268453073 0.079555389365864385;
0.0014452051461961775 0.0028677243059421929 0.0071059195099525277 0.014134868528229745 ...
0.028149902485428785 0.042143489995637114 0.098064998893735253;
0.0019305793044475264 0.0038654804342955224 0.0096915251056551334 0.019439727316775662 ...
0.039007713832494059 0.058629460927678553 0.13738134183824333;
0.0025020721096050808 0.0050299267323266651 0.012654857267640634 0.02542067292452125 ...
0.0510435257542246 0.0767284149515598 0.17974873795853771;
0.0037672597528130487 0.0075526417223835659 0.018932356940629613 0.037929126577915619 ...
0.0759682952336209 0.11403727534491258 0.26644307816087959;
0.0062373784033877607 0.012477153937999945 0.031199269423554773 0.0624063106059884 ...
0.12482552364311707 0.18724804181050336 0.43695232360844904;
0.012153601056849095 0.02430720993001835 0.060768045848069011 0.12153610513709463 ...
0.24307227729500588 0.36460844797376918 0.85075317616518231];
figure()
surf(pc,of,c,...
'LineStyle','-',...
'EdgeColor',[0.5 0.5 0.5],...
'FaceColor','interp',...
'FaceAlpha', 0.75)
zmin=min(c(:));
zmax=max(c(:));
xlabel 'P_c [bar]'
ylabel '(o/f)_m'
zlabel '{\rho} [kg/m^3]'
set(gca,'xscale','log','yscale','log')
hold on
number=20;
range=zmax-zmin;
inct=range/number;
contourl=zmin:inct:zmax;
contour3(pc*0.95,of*0.95,c,20,'k')
hold off
colormap (jet(256))

Since you specify 20 contours, I decided to let contour3 calculate those levels itself. I’m not certain that it made much of a difference, though.
.
I can live with that.
Thanks very much for your help on this.
Much appreciated.
As always, my pleasure!
I wish there was a better (at least a more robust) solution.
추가 답변 (0개)
커뮤니티
더 많은 답변 보기: ThingSpeak 커뮤니티
카테고리
도움말 센터 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
제품
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

