-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Y-axis labels are impossible to align by baseline #1734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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. |
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?). |
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. |
(sorry wrong button) |
@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: Agreed. With anchored rotation as the default this issue is solved. |
As the example below shows, axis labels are not aligned by text baseline by default, which would be typographically correct.
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.
The text was updated successfully, but these errors were encountered: