How to set the Z axis length and values constant in a 3D surface plot?

50 次查看(过去 30 天)
I am using a 3D surface plot on 100 matrices (each matrix is 44 by 44). For every matrix, the maximum and minimum value in the Z direction is different and hence when I use the surface plot function, the length of Z axis keeps changing. But I want the length of Z axis and the values on it to remain constant. How to achieve that?

回答(1 个)

Image Analyst
Image Analyst 2016-5-6
Use zlim():
zlim([yourMinZValue, yourMaxZValue]);
  3 个评论
Image Analyst
Image Analyst 2016-5-6
I didn't say use the max value of your data - I said to use the max and min values that you want it to use for all surface plots. So use
zlim([20, 100]);
if the lowest you think any of the 100 plots will go is 20 and the highest you think any of them will ever reach is 100. Call zlim() after after you plot to any axes control regardless of how many axes controls there are.
Javier García Romero
编辑:Javier García Romero 2020-12-29
I have the same problem as Jasnoor Singh (I'm plotting a damped 3D sine wave) and the solution you gave doesn't work for me. This is what I coded, and the zlim I get in the plot are approx [-2, 3.5] instead of [-5, 5]:
clc
clear
x=-4*pi:0.1:4*pi;
y=-4*pi:0.1:4*pi;
[X,Y]=meshgrid(x,y);
R=sqrt(X.^2+Y.^2);
Z=5*exp(-R/5).*sin(R);
s = surf(X,Y,Z,'FaceColor','r','FaceAlpha','0.3','edgecolor','k');
zlim([-5 5]);
xlabel('x')
ylabel('y')
zlabel('z')
axis equal tight
EDIT: I've sorted it out. What is working for me is writing "axis([xmin xmax ymin ymax zmin zmax])" at the end instead of using zlim, so now it looks like this:
clc
clear
x=-4*pi:0.1:4*pi;
y=-4*pi:0.1:4*pi;
[X,Y]=meshgrid(x,y);
R=sqrt(X.^2+Y.^2);
Z=5*exp(-R/5).*sin(R);
s = surf(X,Y,Z,'FaceColor','r','FaceAlpha','0.3','edgecolor','k');
xlabel('x')
ylabel('y')
zlabel('z')
axis([-4*pi 4*pi -4*pi 4*pi -5 5])

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by