How to resize one axis and keep proportionality?

13 views (last 30 days)
I would like to change my axis' position and size but keep the Y axis proportion with
axis equal
The only way I found to do that was
set(gca,'Units','normalized','Position', [0 0 1 1]);
axis equal
But with this method, the Y-axis is kept to 1 and the X-axis is resized to keep the proportions.
I would like the exact contrary: let the X-axis to 1 and resize the Y-axis with the proportionality.
Any idea to help me?
  1 Comment
Gautam Mohan
Gautam Mohan on 29 Mar 2016
If I am understanding you correctly, you want the Y-axis to be dependent on the X-axis, instead of the other way around.
The simplest way to do this might be to just set the 'YLim' property of the axis. Once you have the XLim and YLim properties, you can do any desired math and reset the values accordingly. For instance, a simple routine to resize the Y-axis to be the same as the X-axis looks like this:
ax = gca; %get the axis
ax.YLim = ax.XLim %set the limits of the Y-axis to be that of the X-axis
More information about axis properties can be found here.

Sign in to comment.

Accepted Answer

lfaure
lfaure on 5 Apr 2016
Hi,
Thank you all for your answers. I tried them all but it did not work. I tried it with other parameters. It turns out the one I was looking for is:
set(gca,'Units','normalized','Position', [0 -0.5 1 2]);
I am not sure why this is it, but it works very well for my specific case...

More Answers (1)

Chad Greene
Chad Greene on 29 Mar 2016
What if you set axis equal before setting axis position? Then you can tinker with xlim however you please.
This is what I'm thinking:
imagesc(peaks)
axis equal
set(gca,'Units','normalized','Position', [0 0 1 1]);
xlim([20 40])

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!