Same aspect ratio for the z-axis in a surface plot

I have a surface plot
and the x-axis and y-axis have the same ratio. I wish for the z-axis to have the same ratio. I have used
daspect ([1 1 1])
but it turns into a 2D plot.
I have used this code for the same aspect ratio for the x-axis and y-axis.
h=get(gca,'DataAspectRatio');
if h(3)==1
set(gca,'DataAspectRatio',[1 1 1/max(h(1:2))])
else
set(gca,'DataAspectRatio',[1 1 h(3)])
end

3 commentaires

Alexandra Roxana
Alexandra Roxana le 9 Juin 2023
Déplacé(e) : Star Strider le 9 Juin 2023
maybe you get a 2D plot because the range of your z axis is 1000 times smaller than the range of x, y axes
@Mathieu NOE It still should be a solution for this.

Connectez-vous pour commenter.

 Réponse acceptée

As mentioned by Mathieu NOE in the comment section, your z-axis data is 1000 times smaller than the range of x and y-axes data. Hence the ratio between them should be rescale accordingly.
Check whether this is what you want or not.
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
surface(X/5+1,Y/3.5,Z*1e-3) % Just make sure the range of the demo data is close to your data
view(3)
daspect ([1 1 1e-3]);

10 commentaires

That seems to work. It would help me if the values would be multiplied by 10^-3; is there a way to do that?
Similar approach with exponent of z-axis properly selected.
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
surface(X/2.5,Y/1.8,Z*1e-2) % Just make sure the range of the demo data is close to your data
view(3)
ax=gca;
ax.ZAxis.Exponent = -2; % Set the expoent to -2 here
daspect ([1 1 1e-2]);
I'm afraid it isn't right: let's say a measure unit from the x-axis or y-axis is 1cm, on the z-axis is 0.01 cm so it isn't right. They have to be equal, for my surface plot it needs to be that way so some points won't be that isolated.
According to your requirement, you should use:
%daspect ([1 1 1])
But I think it is not an optimal way to present the data, see the example below and the last plot is what you need.
tiledlayout(2,2,'TileSpacing','none');
[X,Y,Z] = peaks(20);
nexttile
surf(X,Y,Z*1e-3)
daspect ([1 1 1e-3]);
nexttile
surf(X,Y,Z*1e-3)
daspect ([1 1 1e-2]);
nexttile
surf(X,Y,Z*1e-3)
daspect ([1 1 1e-1]);
nexttile
surf(X,Y,Z*1e-3)
daspect ([1 1 1e-0]);
I see what you mean and indeed, daspect messes up also the x and y-axis. Maybe if I use a smaller step for each axis might it work?
Imaging you put two 1 m rulers on the floor as the x and y-axis and your data on z-axis have a thickness like a sheet of paper, then you ask the program to display the entire data on a volume of 1 cubic meter. Then you can only find something near the floor and that's why you got a "2D" plot. So function daspect does a correct job without messes up anything on x,y and z-axis.
I do not have an answer for your question and I would recommend you to think how you would like to present your data.
That makes perfect sense! Thank you for all your explanations!
I guess I have to work with the time step; I think if the time step was very small on the x or y-axis, the z-axis would be well defined.
Glad to see you come up with a new idea. Just curious your data along z-axis is also in time unit?
Alexandra Roxana
Alexandra Roxana le 10 Juin 2023
Modifié(e) : Alexandra Roxana le 10 Juin 2023
No, it is the solution so it doesn't work. I'm thinking at how I could plot this if for instance, I would measure on a piece of paper with a ruler, this is how I would like for it to look. The grid should be very detailed. This is how a part of the solution looks like:

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by