필터 지우기
필터 지우기

How to show the plot at a specific height of a 3D plot?

조회 수: 10 (최근 30일)
harry wang
harry wang 2015년 11월 19일
댓글: Kelly Kearney 2016년 7월 13일
Hi There,
I have a 3D plot as follow:
x=0:10;
y=0:10;
[X,Y]=meshgrid(x,y);
z=X.^2+Y.^2;
surf(x,y,z)
How can I show the 2D plot (XY plot) at a specific height(z) such as z=100?
Thanks.

답변 (2개)

Star Strider
Star Strider 2015년 11월 20일
You can combine the surf plot with a contour3 plot to overplot the specific contour at the level you want:
x=0:10;
y=0:10;
[X,Y]=meshgrid(x,y);
z=X.^2+Y.^2;
surf(X,Y,z) % Draw Surface
hold on
contour3(X,Y,z,[100 100], '-r', 'LineWidth',2) % Draw Contour At ‘100’
hold off

Walter Roberson
Walter Roberson 2015년 11월 20일
contour(x, y, z, [100 100])
Note that I had to use repeat the 100. If you were to call
contour(x, y, z, 100)
then that would mean that it should pick 100 different contour levels. The way that contour tells whether you are asking for a specific number of levels or if you are asking for a particular location for the contours is that it treats a scalar as being the number of contours and any vector as being the list of locations to place the contours at. So to get a contour at z = 100 we needed to make a vector out of the 100 by repeating it.
If you were asking about different levels such as 100 and 150 then you would not need to repeat them:
contour(x, y, z, [100 150])
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 7월 13일
I do not understand the distinction between "the contour level specified by h" and "all the levels at height h" ? If you have region that rises from below h to above h, then contour(x, y, z, [h h]) will plot around it at the height that corresponds to h.
Kelly Kearney
Kelly Kearney 2016년 7월 13일
Do you mean you want to plot a contour plot, but instead of putting the contours at Z=0, you want them at a specified height? In newer versions of Matlab, you need to dive into some undocumented properties to do this:
[x,y,z] = peaks;
surf(x,y,z);
shading flat;
hold on;
h = 5;
[c,hc] = contour(x,y,z);
drawnow;
for ii = 1:length(hc.EdgePrims)
hc.EdgePrims(ii).VertexData(3,:) = h;
end
Alternatively, you could use the data in c with plot3 to create contour-like lines. Might be a more robust solution than above.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by