Filter löschen
Filter löschen

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

36 Ansichten (letzte 30 Tage)
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?

Antworten (1)

Image Analyst
Image Analyst am 6 Mai 2016
Use zlim():
zlim([yourMinZValue, yourMaxZValue]);
  3 Kommentare
Image Analyst
Image Analyst am 6 Mai 2016
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 am 29 Dez. 2020
Bearbeitet: Javier García Romero am 29 Dez. 2020
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])

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by