6

I have several subplots (one beneath the other), and the y-axis of each subplots ticks with different values (say the first is 1:5 and the second is 10:1000 etc.)

So the result is that each ylabel will have different alignment. Is there a way to fix this? For example - to align all the ylabels to the left? Or is there another solution?

Peter G.
  • 14,786
  • 7
  • 57
  • 75
RNTL
  • 73
  • 1
  • 1
  • 3

3 Answers3

3

Try this:

xpos = -18 % (find this out from get(yl,'pos') on the desired label x-location)
yl=ylabel('Label Here')
pos=get(yl,'Pos')
set(yl,'Pos',[xpos pos(2) pos(3)])

similarly, do this for each subplot. You will find the x-location is retained throughout, and the other positions are default.

Matti Lyra
  • 12,828
  • 8
  • 49
  • 67
Aclariont
  • 31
  • 1
2

To position the ylabel use

 ylabel('my label', 'position',[x y z])
H.Muster
  • 9,297
  • 1
  • 35
  • 46
  • But i don't want to position the subplots. these are fine. The labels are those which i wish to align. – RNTL May 17 '12 at 12:13
  • I'm rephrasing the question - when you draw several subplots, one beneath the other, if the yticks of the subplots are not on the same scale, then the ylabels of the subplots will be misaligned vertically. and the question is, how to avoid it, without changing the location of the plots themselves. – RNTL May 17 '12 at 12:42
  • Yes, I understand now and the latest update of my answer specifically addressed your problem. You can position the ylabel with its own `position` property (see my answer for the code). Vary the `x` argument to vertically align the labels. – H.Muster May 17 '12 at 13:58
2

This is answered here pyplot axes labels for subplots

use

ax1.get_yaxis().set_label_coords(-0.1,0.5) ax2.get_yaxis().set_label_coords(-0.1,0.5)

It will align at the same y coordinates as original subplot.

Community
  • 1
  • 1