フィルターのクリア

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 Center および File ExchangeIntroduction 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