-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
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
import matplotlib.pyplot as plt
from matplotlib.transforms import Bbox
from copy import deepcopy
# Generic plot
plt.plot(range(6),range(6), marker='o')
plt.xlim(0, 5)
plt.ylim(0, 5)
ax = plt.gca()
# Original Code to expand the clipping box
# oldpts = ax.bbox.get_points()
# oldpts[1, 1] *= 1.05
# newbbox = Bbox(oldpts)
# Simple code to just copy the old bounding box
newbbox = deepcopy(ax.bbox)
for o in ax.lines:
o.set_clip_box(newbbox)
# Save SVG
plt.savefig("test.svg")
# Show plot
plt.show()
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