Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

axis equal only in xy-plane?

2,387 views
Skip to first unread message

HK

unread,
Feb 21, 2011, 4:57:12 AM2/21/11
to
Hi all,

I'd like to apply axis equal command only to x- and y-axis. I'm doing plot3s where the z-axis is significantly 'higher' than the x- and y-axis, but I'd like the ratio of the former to be equal.

Is there a way to apply the axis equal to only x- and y-axis?


Thanks in advance.

HK

unread,
Feb 22, 2011, 2:03:05 AM2/22/11
to
Is this one those stupid questions that everyone should be able to solve?

Or is it just that I didn't articulate my problem clearly...

I mean I'd like the x- and y-axis to equal in the sense that the interval between the axis ticks would be the same. However I do not want the Z-axis to scale at the same tick interval as it is in a completely different dimension than the x- and y-axis. I could of course scale the z-axis before plotting but that would compromise the readability of the plot.

HK

unread,
Feb 22, 2011, 2:29:04 AM2/22/11
to
I probably should have said that I've experimented with 'axis vis3d' and the DataAspectRatio -property, but they don't lock the axis the way I'd like to

Steven_Lord

unread,
Feb 22, 2011, 9:38:58 AM2/22/11
to

"HK " <zalaz...@yahoo.com> wrote in message
news:ijvn39$124$1...@fred.mathworks.com...


> Is this one those stupid questions that everyone should be able to solve?

It's a question that you asked during a United States federal holiday, so
many of the regular readers were probably off work for the day.

http://en.wikipedia.org/wiki/Washington%27s_Birthday

> Or is it just that I didn't articulate my problem clearly...
> I mean I'd like the x- and y-axis to equal in the sense that the interval
> between the axis ticks would be the same. However I do not want the Z-axis
> to scale at the same tick interval as it is in a completely different
> dimension than the x- and y-axis. I could of course scale the z-axis
> before plotting but that would compromise the readability of the plot.

Adjust the DataAspectRatio and PlotBoxAspectRatio properties of the axes.

http://www.mathworks.com/help/techdoc/ref/axes_props.html#DataAspectRatio

http://www.mathworks.com/help/techdoc/ref/axes_props.html#PlotBoxAspectRatio

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Ingo Schupp

unread,
Jun 17, 2013, 11:30:10 AM6/17/13
to
As this was my first Google hit when searching for the answer to your question, and since the answer by Steven_Lord seems incomplete to me, I will post my own answer after having experimented with the 'DataAspectRatio' axes property.
Apparently, using 'axis square' sets 'DataAspectRatio' like this:

set(gca, 'DataAspectRatio', [diff(get(gca, 'XLim')) diff(get(gca, 'YLim')) diff(get(gca, 'ZLim'))])

which does the right thing to the Z axis, while 'axis equal' sets it to [1 1 1], which does the right thing to the X and Y axes.

What I want is a mixture of both: setting an 'equal'-like ratio between X and Y but keep Z 'square'-like with respect to the smaller (or greater) of the two values for X and Y. This can be achieved with an ugly one-liner:

set(gca, 'DataAspectRatio', [repmat(min(diff(get(gca, 'XLim')), diff(get(gca, 'YLim'))), [1 2]) diff(get(gca, 'ZLim'))])

You might want to use 'max' instead of 'min' depending on your scenario.
Also, appending 'axis vis3d' might be a good idea.

Quang Hanh

unread,
Jun 27, 2013, 4:13:07 AM6/27/13
to
Thanks Ingo, this really helps. I just propose what may be simpler:
Note that if we want axis equal for x and y axes only, the dx and dy should be equal. Besides, we would like the z-axis to be shown (somewhat) proportional to the smaller dimensions between x and y. Assume x is the smaller dimension:

set(gca, 'DataAspectRatio', [diff(get(gca, 'XLim')) diff(get(gca, 'XLim')) diff(get(gca, 'ZLim'))])

would give what expected.

"Ingo Schalk-Schupp" wrote in message <kpna22$mpk$1...@newscl01ah.mathworks.com>...

dgol...@gmail.com

unread,
Jan 16, 2014, 8:35:53 PM1/16/14
to
Here's a one-liner
daspect([max(daspect)*[1 1] 1])

See http://www.mathworks.com/help/matlab/ref/daspect.html

Ethan Thibaudeau

unread,
Dec 16, 2015, 11:35:15 AM12/16/15
to
dgol...@gmail.com wrote in message <5862620f-25ee-45ef...@googlegroups.com>...
> Here's a one-liner
> daspect([max(daspect)*[1 1] 1])
>
> See http://www.mathworks.com/help/matlab/ref/daspect.html

Perfect, Thanks!

Massimo Ciacci

unread,
Dec 20, 2016, 7:32:07 PM12/20/16
to
Perfect tip, indeed 'axis square' is what i needed too.
Thanks!

"Ingo Schalk-Schupp" wrote in message <kpna22$mpk$1...@newscl01ah.mathworks.com>...
0 new messages