Align ylabels

Sture Lygren <sture@...1466...> writes:

Quick question - how can I align ylabels for several subplots?

Set their position properties e.g. like this:

  y = ylabel('foo')
  pos = getp(y, 'position')
  setp(y, 'position', (pos[0], X))

where X is the position (in data coordinates) where you want the
label. Depending on what kind of alignment you want, you may want to
set the verticalalignment property -- to see the properties and the
kind of values they can take, type setp(y), and to see their current
values, type getp(y).

If your subplots have different scales, you will want to set the
transform property, which is a little bit more complicated; there
are examples at

  http://www.scipy.org/Cookbook/Matplotlib/Transformations

···

--
Jouni K. Sepp�nen

Hi,

Thanks a lot for your reply. I still have some problem tough. I want
vertical alignment of 5 ylabels for 5 different subplots. Trying your
solution I'm able to move the ylabels up/down but not right/left. Seems
like changing 'x' in position (x,y) has no effect at all. How come?

regards,
Sture

Jouni K. Sepp�nen wrote:

···

Sture Lygren <sture@...1466...> writes:

Quick question - how can I align ylabels for several subplots?

Set their position properties e.g. like this:

  y = ylabel('foo')
  pos = getp(y, 'position')
  setp(y, 'position', (pos[0], X))

where X is the position (in data coordinates) where you want the
label. Depending on what kind of alignment you want, you may want to
set the verticalalignment property -- to see the properties and the
kind of values they can take, type setp(y), and to see their current
values, type getp(y).

If your subplots have different scales, you will want to set the
transform property, which is a little bit more complicated; there
are examples at

  http://www.scipy.org/Cookbook/Matplotlib/Transformations

--
Sture Lygren
Computer Systems Administrator
Andoya Rocket Range
Work: +4776144451 / Fax: +4776144401

Should be horizontal alignment ...

Sture Lygren wrote:

···

Hi,

Thanks a lot for your reply. I still have some problem tough. I want
vertical alignment of 5 ylabels for 5 different subplots. Trying your
solution I'm able to move the ylabels up/down but not right/left. Seems
like changing 'x' in position (x,y) has no effect at all. How come?

regards,
Sture

Jouni K. Sepp�nen wrote:

Sture Lygren <sture@...1466...> writes:

Quick question - how can I align ylabels for several subplots?

Set their position properties e.g. like this:

  y = ylabel('foo')
  pos = getp(y, 'position')
  setp(y, 'position', (pos[0], X))

where X is the position (in data coordinates) where you want the
label. Depending on what kind of alignment you want, you may want to
set the verticalalignment property -- to see the properties and the
kind of values they can take, type setp(y), and to see their current
values, type getp(y).

If your subplots have different scales, you will want to set the
transform property, which is a little bit more complicated; there
are examples at

  http://www.scipy.org/Cookbook/Matplotlib/Transformations

--
Sture Lygren
Computer Systems Administrator
Andoya Rocket Range
Work: +4776144451 / Fax: +4776144401

The ylabel position is layed out to not overlay the y tick labels --
if these are in different positions on each axes you will get the
ylabel in different positions. Two solutions:

1) insure all the yticklabels have the same width by using a custom
formatter that fixes the tick widths.

  from matplotlib.ticker import FormatStrFormatter
  ax.yaxis.set_major_formatter(FormatStrFormatter('%1.3f'))

  2) do not use ylabels, but create your own using custom text
instances for labels

  ax.text(-0.1, 0.5, 'my label', transform=ax.transAxes, rotation=90,
ha='right', va='center')

The 2nd one is probably what you want.

JDH

···

On 2/27/07, Sture Lygren <sture@...1466...> wrote:

Thanks a lot for your reply. I still have some problem tough. I want
vertical alignment of 5 ylabels for 5 different subplots. Trying your
solution I'm able to move the ylabels up/down but not right/left. Seems
like changing 'x' in position (x,y) has no effect at all. How come?