You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Y-axis labels are impossible to align by baseline #1734
For the x-axis labels, alignment by baseline is possible to configure (code below), but it seems to be impossible to do for y-axis labels, because set_horizontalalignment("baseline") is not allowed.
I've labelled this as a confirmed bug because this behaviour is a surprise to me - I'd be interested in seeing if we can use the baseline vertical alignment for labels as default.
I am using TkAgg (I put "print matplotlib.get_backend()" just above pylab.show() to find out), but the figure I get is exactly the same as what I uploaded in the previous comment.
My apologies @jpaalasm - I was in the middle of doing some mpl development and wasn't able to try this out on v1.3. I can see the same behaviour in mpl v1.2.1.
Interestingly, this behaviour was changed by @pwuertz in b9fba92. I'm afraid I don't know of a workaround for using anything other than the master repository.
Yea, this scenario was one of the reasons why I proposed this anchored-rotation patch. With the default text rotation model up to matplotlib v1.2 the rotated text is aligned by its bounding box in the un-rotated system. There is no way to define a baseline there.
There should be a workaround for v1.2 by applying the same settings found in b9fba92. Try something like this:
Hopefully this works for you, but be aware that this change may trigger some bugs. I remember one or two follow-up patches that had to be applied to v1.3.
@pelson I guess the reason for not making baseline the default alignment is that matplotlib uses a fixed layout by default. So if you set 'baseline' instead of 'top' for the xlabel and include some huge symbol (maybe an integral sign), it will probably collide with the graph or the ticks. You'd have to use tight_layout for more reliable positioning.
It seems that setting the va to baseline works on master, so I think we can consider this closed. @jpaalasm, @pwuertz: do you agree?
We probably will want to move to using baseline as the default in a future release of matplotlib. Maybe we should create a new 1.4.x targetted issue for that?
@mdboom: Agreed. With anchored rotation as the default this issue is solved.
A new issue for 1.4.x could discuss the side-effects I raised above concerning default-baseline.
Activity
jpaalasm commentedon Mar 13, 2013
Here's a screenshot that shows the incorrect label alignment.
pelson commentedon Mar 13, 2013
Because the text is rotated on the yaxis, you still want to use vertical alignment for the y labels. Adding:
Seems to do the trick for me. Can you confirm?
I've labelled this as a confirmed bug because this behaviour is a surprise to me - I'd be interested in seeing if we can use the baseline vertical alignment for labels as default.
Thanks for raising @jpaalasm.
jpaalasm commentedon Mar 13, 2013
Well, that does not work, because verticalalignment is not vertical with respect to the rotated text, but with respect to the figure.
It produces the following result (matplotlib 1.2.0).
pelson commentedon Mar 13, 2013
Definitely works for me. Are you using the Macos backend by any chance? Are you able to confirm that this work for you on any Agg backend (TkAgg?).
jpaalasm commentedon Mar 13, 2013
I am using TkAgg (I put "print matplotlib.get_backend()" just above pylab.show() to find out), but the figure I get is exactly the same as what I uploaded in the previous comment.
pelson commentedon Mar 13, 2013
My apologies @jpaalasm - I was in the middle of doing some mpl development and wasn't able to try this out on v1.3. I can see the same behaviour in mpl v1.2.1.
Interestingly, this behaviour was changed by @pwuertz in b9fba92. I'm afraid I don't know of a workaround for using anything other than the master repository.
pwuertz commentedon Mar 13, 2013
Yea, this scenario was one of the reasons why I proposed this anchored-rotation patch. With the default text rotation model up to matplotlib v1.2 the rotated text is aligned by its bounding box in the un-rotated system. There is no way to define a baseline there.
There should be a workaround for v1.2 by applying the same settings found in b9fba92. Try something like this:
Hopefully this works for you, but be aware that this change may trigger some bugs. I remember one or two follow-up patches that had to be applied to v1.3.
pwuertz commentedon Mar 13, 2013
(sorry wrong button)
pwuertz commentedon Mar 13, 2013
@pelson I guess the reason for not making baseline the default alignment is that matplotlib uses a fixed layout by default. So if you set 'baseline' instead of 'top' for the xlabel and include some huge symbol (maybe an integral sign), it will probably collide with the graph or the ticks. You'd have to use tight_layout for more reliable positioning.
mdboom commentedon May 21, 2013
It seems that setting the
vatobaselineworks onmaster, so I think we can consider this closed. @jpaalasm, @pwuertz: do you agree?We probably will want to move to using baseline as the default in a future release of matplotlib. Maybe we should create a new 1.4.x targetted issue for that?
pwuertz commentedon May 22, 2013
@mdboom: Agreed. With anchored rotation as the default this issue is solved.
A new issue for 1.4.x could discuss the side-effects I raised above concerning default-baseline.