-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Axis ticks are not aligned by baseline #4115
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
cc @pwuertz |
I think I remember a discussion we once had about that. The point is that top-anchoring the individual ticks isn't the correct thing to do in the first place, but it is the default behaviour in matplotlib. The pgf backend is probably the only backend that reports the correct text sizes and thus shows this problem. Ideally one should look for the maximum height of all ticks and base-align all ticks at the same vertical position (or maybe just font-size + margin). |
@jowr: As a workaround, you could manually base-align like you did already and set an appropriate padding for the labels:
|
Thank you all for the quick action. I indeed found the other issues, but I wanted to report a new one since I thought that the other ones were only looking at the axis label and not the ticks. Good luck with your work and keep up the good spirit for matplotlib! |
Thanks for the quick fix. I currently use this code:
since I read somewhere that one should reassign the text after changing the padding... |
Ah, you are absolutely correct. The previous discussions were focused on labels, we shouldn't forget about the ticks. And yes, your quick fix looks good and might be more robust since you are forcing the tick positions to be re-evaluated. |
@tacaswell: This is only a workaround, I don't think this is ready for a PR yet. We need to start/continue a discussion on how to implement base-alignment by default and how to setup the necessary padding, i.e. which usecases are to be covered, which pathological cases are to be ignored. |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
I'd note that the alignment can also be messed up from text rotation. A workaround I have found it to always use rotation_mode='anchor' when rotating text, despite this not normally being necessary in pdf mode. With this option the text alignment lab.set_horizontalalignment("right") seems to work as expected in pgf mode. |
Hi, it looks like the PGF backend defaults to top-align tick labels without accounting for the height of the letters. This works without problems with the PDF backend, also using Tex to render text does not make a difference.
using this Python code:
... and this Tex document:
produces this:

One possible solution could be to use the baseline alignment with some additional padding depending on the font size.
The text was updated successfully, but these errors were encountered: