-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Images are clipped incorrectly with custom clip path #15952
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
At the risk of sounding like a broken record... looks like this doesn't happen with mplcairo? can you confirm? |
I believe you are correct. Also, I think this affects all artists, not just images, but it really depends on how the artist interacts with the border. |
@anntzer coughhumblebragcough 😉 |
hehe... |
As noted in #15970, it was not a full fix, but I couldn't figure out a way to reproduce in plain Matplotlib. Now, I think I have something that still shows the issue. Basically, because the figure background defaults to white, you don't see it, but by changing the background to some other colour, you can see that the image is clipped a bit differently using a clip path over a clip box: import matplotlib.pyplot as plt
from matplotlib.path import Path
import matplotlib.patches as mpatches
from matplotlib.testing import setup as mpl_setup
plt.rcParams['savefig.facecolor'] = 'b'
data = [[1, 1], [0, 1]]
fig, ax = plt.subplots(1, 4, figsize=(8, 2), sharex=True, sharey=True,
facecolor='b')
ax[0].set_xlim(0, 2)
ax[0].set_ylim(0, 2)
ax[0].set_title('Default patch')
for a in ax[2:]:
a.patch = mpatches.PathPatch(
Path([[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]]),
facecolor=plt.rcParams['axes.facecolor'],
edgecolor='None',
linewidth=0,
snap=False,
transform=a.transAxes)
a.patch.set_figure(fig)
a.set_title('Custom patch')
img = []
for a in ax[:3]:
img.append(a.imshow(data, extent=(0, 2, 0, 2), vmin=-10))
for s in a.spines.values():
s.set_bounds(0, 1.25)
img[1].set_clip_box(None)
img[1].set_clip_path(
Path([[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]]),
ax[1].transAxes)
ax[1].set_title('Custom clip path')
ax[3].set_title('No image, clip path')
ax[3].set_aspect('equal')
for s in ax[3].spines.values():
s.set_bounds(0, 1.25)
plt.show() The first So while the patch changing position a bit might explain a few edge differences, it doesn't explain the second |
Indeed, it is snapping that seems to do this. I am mostly worried about the last case though, as it's the (likely, not tried this change on it yet) problem that manifests in Cartopy. |
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! |
Bug report
Bug summary
This is related to #15946, but for images. When setting a custom clip path, the image is cropped slightly incorrectly.
Code for reproduction
(Note, in lieu of subclassing
Axes
andSubplot
, I've just overwritten theAxes.patch
using the properties that it should have).Actual outcome
If you check the antialiasing along the top spine, the first Axes is grey (f1f1f1), but the second and third are slightly yellow (f0e7a0). Note, this seems to be figure size and/or DPI dependent.
Expected outcome
All images should be cropped in the same way, and there should not be a difference in edges along the top of the Axes.
Matplotlib version
print(matplotlib.get_backend())
): TkAgg (probably just Agg though)The text was updated successfully, but these errors were encountered: