Thanks to visit codestin.com
Credit goes to github.com

Skip to content

AxesImage does not respect its clip_box property #14396

@anntzer

Description

@anntzer

Bug report

Bug summary

Regardless of an AxesImage clip_box property value, they are always additionally clipped to their parent Axes' bbox, unlike other artists (e.g. Line2D) who can have a clip_box completely independent of their parent axes.

Code for reproduction

from matplotlib import pyplot as plt

fig, axs = plt.subplots(2, 2)

l, = axs[0, 1].plot([0, 1])
l.set_clip_box(axs[0, 0].bbox)

im = axs[1, 1].imshow([[0, 1], [2, 3]], aspect="auto", extent=(0, 1, 0, 1))
im.set_clip_path(None)
im.set_clip_box(axs[1, 0].bbox)

plt.show()

Actual outcome

The line in axs[0, 1] can be seen in axs[0, 0] by panning axs[0, 1] to the side.
The image in axs[1, 1] cannot be seen in axs[1, 0] (or anywhere else, for that matter) by panning.

Expected outcome

im is correctly clipped to axs[1, 0].

This is likely due to the implementation of AxesImage.make_image

    def make_image(self, renderer, magnification=1.0, unsampled=False):
        # docstring inherited
        trans = self.get_transform()
        # image is created in the canvas coordinate.
        x1, x2, y1, y2 = self.get_extent()
        bbox = Bbox(np.array([[x1, y1], [x2, y2]]))
        transformed_bbox = TransformedBbox(bbox, trans)
        return self._make_image(
            self._A, bbox, transformed_bbox, self.axes.bbox, magnification,
            unsampled=unsampled)

(passing self.axes.bbox as clipping bbox to self._make_image is the problem).

Matplotlib version

  • Operating system: linux
  • Matplotlib version: master
  • Matplotlib backend (print(matplotlib.get_backend())): qt5agg
  • Python version: 37
  • Jupyter version (if applicable): none
  • Other libraries:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions