How to place Contourf at a new height?

2 次查看(过去 30 天)
I have the following plot and the Contourf.
By default, Contourf will always be generated at height Z = 0 i.e. the horizontal plane. I would like to shift Contourf to height Z = -2, this is so the contour will be placed under the graph of my function. How do I achieve this?
Code:
x = linspace(0,1,1000);
y = linspace(0,1,1000);
[X,Y] = meshgrid(x,y);
Z = -X.^2 - Y.^2;
mesh(X,Y,Z)
box on
hold on
contourf(X,Y,Z)

回答(1 个)

Star Strider
Star Strider 2017-4-16
This seems to work:
x = linspace(0,1,1000);
y = linspace(0,1,1000);
[X,Y] = meshgrid(x,y);
Z = -X.^2 - Y.^2;
mesh(X,Y,Z+2)
box on
hold on
contourf(X,Y,Z+2)
zt = get(gca, 'ZTick');
set(gca, 'ZTick',zt, 'ZTickLabel',zt-2)
view([15 35])
Change the view arguments to the orientation you want.
A likely better option is Customizing contour plots part 2 (link).

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by