-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
[Bug]: Clipping mask can shift in PDF and SVG file outputs when Bbox is adjusted #24890
Comments
This is like because the axes clip box is not actually fixed, it depends on the figure size and resolution. The default dpi is 100 (and the target screen units are 'pixels'), but for the vector output the effect dpi is 72 and the target units is pt. When you make the copy (or otherwise get a static bounding box) it will come out wrong. The hacky option is to create the figure at 72 DPI and then you will "get lucky", a more robust solution is to make a transformed box from https://matplotlib.org/stable/tutorials/advanced/transforms_tutorial.html is probably the reference you want. |
That makes sense. Any tips on how to do make a transformed box in the transAxes coordinate system? I've been searching and experimenting and can't get it, even with tips from the tutorial. I've also tried to modify the ax.bbox in place, but it won't allow that. |
I'm a little confused about what you are trying to do. If you remove the deepcopy, the default clipping is as you say you want it. So, what is your actual desired effect that you are messing with the clip box for? |
I think what you are trying to do is simply:
But, I could be misinterpreting. I actually would agree that |
import matplotlib.pyplot as plt
from matplotlib.transforms import Bbox, TransformedBbox
fig, ax = plt.subplots()
bb = TransformedBbox(Bbox([[-.05, -.05], [1.05, 1.05]]), ax.transAxes)
print(bb.get_points())
fig.set_size_inches(5, 5)
print(bb.get_points()) |
That's it! Thanks @jklymak and @tacaswell! Yeah, I can usually figure out how to get MPL to do what I'm looking for, but this one has stumped me for years. Finally thought I got it and then discovered this new issue. Thanks for your help! |
Bug summary
I am trying to adjust the clipping box around markers, which work great for WxAgg and for PNG output. However, when I export in SVG or PDF, the clipping box has shifted up and to the right.
Code for reproduction
Actual outcome
See figure. The 0,0 point is clipped and the 5,5 point is not.
Expected outcome
See figure. Both should be clipped. This is what we see with PNG output and with the plt.show() rendering.
Additional information
When I copy the Bbox and set that as the clip box, it works fine. But, when I deepcopy it, it doesn't.
I opened the SVG file in Illustrator, and there is a clipping box that is shifted up and to the right of the origin. It can be deleted in Illustrator to recover the content below.
I'm definitely open to workarounds. I'm not sure if I'm doing this right, but it seems to work for PNG files, which makes me think there is a glitch in the background somewhere.
Operating system
Windows
Matplotlib Version
3.6.2
Matplotlib Backend
module://backend_interagg
Python version
3.10.8
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: