Skip to content

Images are clipped incorrectly with custom clip path #15952

Closed as not planned
@QuLogic

Description

@QuLogic

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 and Subplot, I've just overwritten the Axes.patch using the properties that it should have).

import matplotlib.pyplot as plt
from matplotlib.path import Path
import matplotlib.patches as mpatches

data = [[1, 1], [0, 1]]

fig, ax = plt.subplots(1, 3, figsize=(6, 2), sharex=True, sharey=True)
ax[0].set_xlim(0, 2)
ax[0].set_ylim(0, 2)
ax[0].set_title('Default patch')

ax[2].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=ax[2].transAxes)
ax[2].patch.set_figure(fig)
ax[2].set_title('Custom patch')

img = []
for a in ax:
    img.append(a.imshow(data, extent=(0, 2, 0, 2), vmin=-10))

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')

plt.show()

Actual outcome

Figure_1

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

  • Operating system: Fedora 30
  • Matplotlib version: 9d00ca8
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg (probably just Agg though)
  • Python version: 3.6.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend: aggstatus: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: inactiveMarked by the “Stale” Github Actiontopic: images

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions