figure with 3 equal outerposition axes pushes third axis off figure

figure;a1=axes('outerposition',[0 0 .333 1]);a2=axes('outerposition',[0.333 0 .333 1]);a3=axes('outerposition',[.666 0 .333 1]);
a3b = axes('position',get(a3,'position'),'yaxislocation','right');
ylabel(a3b,'axis3b');

2 Comments

Why not just use SUBPLOT for each plot?
a few reasons. mostly because the plot layout in this application can get exceedingly complex. another: if you use subplot to produce 1x3 as above, and you create secondary y-axis, the plots don't move around to accommodate them (i believe subplot just sets 'position' and not 'outerposition'). eg if you put a right hand axis on the middle one, its ylabels overlap with the ylabels in the third axes.
either way, this still doesn't answer why matlab isn't honoring what i understand to be the main feature of 'outsideposition'. if you make a figure with two plots in it, as above, the axes always move around so you can always see the various axis labels, title, etc, without overlapping each other and without going off the page.

Sign in to comment.

 Accepted Answer

I don't believe the outer position is updated when you set the y-label. Does this fix your problem?
figure;
a1=axes('outerposition',[0 0 .333 1]);
a2=axes('outerposition',[0.333 0 .333 1]);
a3=axes('outerposition',[.666 0 .333 1],'yaxislocation','right');
ylabel(a3,'axis3b');
It fixed it for me.

3 Comments

close. this got me half way there.
since i was setting a3b's POSITION and not outerpostion, it didn't reset the actual axis lines and put the label inside of any dictated outerposition.
basically to do what i want (any axis can have 2 y axes). i have to set the first axes outerposition as above. then set the right-hand yaxis axes outerposition to the same. then after setting the limits, labels, etc, i have to reset a3 axes POSITION to a3b position.
i think this is creating a chicken/egg problem in making sure the axis lines/ticks overlap properly.
example:
axW = .5;
figure;a1=axes('outerposition',[0 0 axW 1]);a2=axes('outerposition',[axW 0 axW 1]);
a2b = axes('position',get(a2,'position'),'yaxislocation','right');
ylabel(a2b,'huh')
set(a2,'outerposition',[axW 0 axW 1]);
set(a2b,'outerposition',get(a2,'outerposition'));
set(a2,'position',get(a2b,'position'));
subplot and plotyy don't do anything that axes() doesn't do.
and my comment above saying this works isn't exactly true. by setting a2b position to a2's position, a2b's outerposition is now altered and may not be inside the figure.
i guess i have to "unaccept" this answer...

Sign in to comment.

More Answers (1)

above accepted answer doesn't actually work for me. see my last comment in answer above...
so, does anyone know how to keep the entirety of two axes (one for left hand y axis, one for right hand) inside of a region while keeping their 'positions' aligned?

1 Comment

this is a problem in my current code because we use set()/ylabel/etc to subsequently tack things onto the outside of the axes. these are sometimes not known before we place the axes. sometimes the 'tightinset' of these items can be large.
i'll try a few more things, but if anyone has ideas, i'd be appreciative..

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!