Skip to content

Fix image bbox clip. #14774

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

Merged
merged 1 commit into from
Aug 6, 2019
Merged

Fix image bbox clip. #14774

merged 1 commit into from
Aug 6, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jul 14, 2019

Closes #14396.

The baseline image change was due to previously off-by-one clipping, as
can be checked by additionally drawing a line with the same clipbox and
checking that the image was clipped one pixel row/column too far:

from matplotlib import pyplot as plt, patches

fig, ax = plt.subplots()
d = [[1, 2], [3, 4]]

im = ax.imshow(d, extent=(0, 5, 0, 5), cmap="viridis")
l, = ax.plot([0, 5], [0, 5])

rect = patches.Rectangle(
    xy=(1, 1), width=2, height=2, transform=im.axes.transData)
im.set_clip_path(rect)
l.set_clip_path(rect)

plt.show()

oldnew

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer force-pushed the image-clip branch 3 times, most recently from 152a08c to 47c3a3b Compare July 15, 2019 08:17
The baseline image change was due to previously off-by-one clipping, as
can be checked by additionally drawing a line with the same clipbox and
checking that the image was clipped one pixel row/column too far:

    from matplotlib import pyplot as plt, patches

    fig, ax = plt.subplots()
    d = [[1, 2], [3, 4]]

    im = ax.imshow(d, extent=(0, 5, 0, 5), cmap="viridis")
    l, = ax.plot([0, 5], [0, 5])

    rect = patches.Rectangle(
        xy=(1, 1), width=2, height=2, transform=im.axes.transData)
    im.set_clip_path(rect)
    l.set_clip_path(rect)

    plt.show()
@dstansby dstansby added this to the v3.2.0 milestone Aug 6, 2019
@dstansby dstansby merged commit dc1bf99 into matplotlib:master Aug 6, 2019
@anntzer anntzer deleted the image-clip branch August 6, 2019 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AxesImage does not respect its clip_box property
3 participants