How to scale y-axes in subplots so that the length of one data unit is equal between the different subplots.

10 views (last 30 days)
I made stacked bar plots in three subplots. I have two problems which I cannot seem to solve using daspect or pbaspect. Problem 1 is about scaling of data units: On the y-axes I have the depth at which the samples (sediments) were taken. I would like to have an equal scale on the y-axes. For example, if the y-axis range of subplot A is 0 to 50 cm and that of subplot B is 0 to 200 cm, the length of the y-axis of subplot B should be 4 times that of subplot A.
Problem 2 is about automatically setting the position of the subplots: subplot A to C should all have the 0cm depth mark at the same height position in the plot.
The problem with changing the data aspect ratio (daspect) or the axes equal command is that these commands work per subplot => thus you cannot obtain equal y-axis scale for all subplots.
Note: I want all x-axes of the subplots to have the same length (they have equal data range from 0 to 1 so currently they have equal length. However, if I play around with daspect and axes equal the lengths are not equal anymore because these commands work per subplot). See attached file for the current figure and some additional information I added.
  1 Comment
Adam
Adam on 21 Jun 2017
By the sounds of it the simplest option to achieve both would be to simply set all axes to the same limits, defined by the min and max across all sets of data. You are going to have blank space anyway to shrink axes or shift them to match, but shifting axes to line up y ticks is not a trivial problem. It is doable with enough effort, but you'd have to position axes yourself rather than using subplot and it seems a lot more complicated than just setting them all to the same limits.
doc linkaxes
may be of use also.

Sign in to comment.

Accepted Answer

dpb
dpb on 21 Jun 2017
Basically Adam's comment as Answer with a little detail...
for i=1:3
hAx(i)=subplot(1,3,i);
% create the plot code here
...
end
linkaxes(hAx,'y')
set(hAx,'ylim',[0 200])
will leave all with the same axes and meet your objective. Now the result of the linkaxes call is that if you muss around with one axes either programmmatically or manually, the others will stay in synch with it--if you execute
set(hAx(1),'ylim',[0 100])
to zoom by 2X, then the others will also.
  1 Comment
Hans van Hateren
Hans van Hateren on 23 Jun 2017
Thanks a lot. I just had to let go of the idea of having the y-axis on the smaller range plot smaller as well. It looks good with all the y-axes the same length.

Sign in to comment.

More Answers (0)

Categories

Find more on Axes Appearance 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!