필터 지우기
필터 지우기

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

조회 수: 36 (최근 30일)
Jasnoor Singh
Jasnoor Singh 2016년 5월 6일
편집: Javier García Romero 2020년 12월 29일
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일
편집: 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