-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Saving plot as PNG file prunes tick labels #12564
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
Feel free to provide a minimal verifiable example, which allows to reproduce the probem. Else, I see little chance to help here. |
Try increasing your dpi on the png. There is some weird dpi-dependent code for adding or dropping ticks. One of my prs fixes it though I’m not sure if it’s been merged yet. EDIT: Not merged: #12158 |
It is indeed related to the DPI I set. But it is the other way around you suggested. Up to 80 DPI everything is fine. Above that, the tick labels are pruned. Weird. I would try to come up with a reproducible example. |
You probably don't need to - its a known issue... From my testing, I think its an issue of your upper ylimit limit being close, but less than, 1.25. When you decrese the dpi, your upper limit becomes within 1/2 a pixel of 1.25 and includes the 1.25; when you increase the dpi your upper limit is no longer within 1/2 a pixel, and it gets trimmed. #12158 will always trim that tick because your upper y-limit < 1.25. Of course, if you manually specify set_ylim([0, 1.25]) it will not be trimmed. I think that is the correct and consistent behaviour. |
Thank you. That worked. |
Bug report
Bug summary

When I export a plot to PNG, some tick labels are pruned. This does not happen if I use another format, such as PDF or SVG.
Code for reproduction
I failed to recreate the problem with a dummy dataset. It seems that the problem is very much an edge case probably. This is what I see on my Jupyter notebook:
The plot is exported nicely in PDF: test.pdf
But, if I use PNG, the bottom and upper y-tick labels are pruned:

I tried to play around with the padding in
plt.tight_layout()
and the options inplt.savefig()
without success.Matplotlib version
The text was updated successfully, but these errors were encountered: