moving label for secondary axis

10 views (last 30 days)
MMARTINC
MMARTINC on 20 Oct 2016
Edited: dpb on 29 Oct 2016
Hi,
I'm shocked by how unobvious this is, so sorry for asking. I created a multiple plot figure with double axis, and all share the same label for it, as you can see in the figure. I'd like to move the label for that axis to make it more centered. Is there a way to control that from the editor? I dived into the plot browser, but I can only modify the tick labels, not the axis label. Any ideas?
Thank you in advance!!

Accepted Answer

dpb
dpb on 20 Oct 2016
Edited: dpb on 21 Oct 2016
The axis labels are centered on the axis to which they're attached. It appears you used the third (2nd from bottom) subplot to attach the label to.
You can move the label via the editor manually, but programmatically, it's possible by changing the 'position' property of the label. The second value of the three-vector is the vertical location for the center of the label computed to center it on that axes in units of data coordinates. This is quite inconvenient for multiple plots where the data values aren't the same and there are multiple axes. The best idea I've got programmatically would be to
  1. retrieve the axes positions for the bottom and top axes;
  2. compute the vertical extent of these and then
  3. write the label using that position with normalized coordinates
...[former manner elided for brevity...the following is much better]...
The only other solution that eases some of those problems but has other complexities is that one could create another axes of the same extent vertically as the range of the bottom and top subplots but laying to the right of the RH axes. There's an example in the documentation that overlays another axes in the middle of a 2x2 grid that outlines the basic procedure. In this case, with that axes of that overall height, the ylabel would automagically be centered vertically.
There's a File Exchange submission for super titles that addresses the issue for titles not being associated with each axes but overall; whether somebody may have submitted similar for legends or not I don't know; undoubtedly worth a search to see what could find.
ADDENDUM
As noted, had a few minutes and looked at the added-axes option a little more in depth...
for i=1:4,hA(i)=subplot(4,1,i);end
pos1=get(hA(1),'position'); % extents of top axes
pos4=get(hA(4),'position'); % and bottom
pos=[pos4(1:3) pos1(2)+pos1(4)-pos4(2)]; % overall extent of all axes
hAOuter=axes('position',pos,'visible','off'); % invisible one overlaying those
hL=ylabel(hAOuter,'Charcoal index','fontsize',12,'visible','on');
NB: 'visible','on' in the ylabel properties; it'll be 'off' by default as its value is inherited from the parent axes that we made invisible.
  8 Comments
MMARTINC
MMARTINC on 29 Oct 2016
Thanks :-). I sometimes struggle to follow some of the basics, because I started just having to get things done and looking for ways of achieving it. I'll (hopefully) soon have the time to make sense of these kind of things so I don't find myself in these situations :-D. I really appreciate that you put such an effort to help me, I hope I didn't annoy you too much!! All the best!!
dpb
dpb on 29 Oct 2016
I'd note that spending some time reading thru the tutorial "Getting Started" doc will pay large dividends in speeding up the process of, well, "getting started". :) It'll be quicker payback than time simply hunting for some solution or having to post queries in terms of return for effort...

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!