How to show the plot at a specific height of a 3D plot?
13 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(2 个)
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
0 个评论
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
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
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 Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!