diff --git a/doc/api/next_api_changes/behavior/19375-AL.rst b/doc/api/next_api_changes/behavior/19375-AL.rst new file mode 100644 index 000000000000..c543f57d3818 --- /dev/null +++ b/doc/api/next_api_changes/behavior/19375-AL.rst @@ -0,0 +1,2 @@ +``Figure.suppressComposite`` now also controls compositing of Axes images +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index f72e2950100f..a199b350098b 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -3087,7 +3087,8 @@ def draw(self, renderer=None, inframe=False): a.draw(renderer) renderer.stop_rasterizing() - mimage._draw_list_compositing_images(renderer, self, artists) + mimage._draw_list_compositing_images( + renderer, self, artists, self.figure.suppressComposite) renderer.close_group('axes') self.stale = False diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 3e03f7a7f198..b776adfe0434 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2094,7 +2094,8 @@ def draw(self, renderer): try: renderer.open_group('subfigure', gid=self.get_gid()) self.patch.draw(renderer) - mimage._draw_list_compositing_images(renderer, self, artists) + mimage._draw_list_compositing_images( + renderer, self, artists, self.figure.suppressComposite) for sfig in self.subfigs: sfig.draw(renderer) renderer.close_group('subfigure') @@ -2118,7 +2119,7 @@ class Figure(FigureBase): The `.Rectangle` instance representing the figure background patch. suppressComposite - For multiple figure images, the figure will make composite images + For multiple images, the figure will make composite images depending on the renderer option_image_nocomposite function. If *suppressComposite* is a boolean, this will override the renderer. """ diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index e755b204ab9d..009f7190552e 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -150,7 +150,7 @@ def flush_images(): for a in artists: if (isinstance(a, _ImageBase) and a.can_composite() and - a.get_clip_on()): + a.get_clip_on() and not a.get_clip_path()): image_group.append(a) else: flush_images() diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 36ad1aadaa4c..08f0c4da1dc3 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -11,6 +11,7 @@ from numpy.testing import assert_array_equal from PIL import Image +import matplotlib as mpl from matplotlib import ( _api, colors, image as mimage, patches, pyplot as plt, style, rcParams) from matplotlib.image import (AxesImage, BboxImage, FigureImage, @@ -506,6 +507,18 @@ def test_image_composite_alpha(): ax.set_ylim([5, 0]) +@check_figures_equal(extensions=["pdf"]) +def test_clip_path_disables_compositing(fig_test, fig_ref): + t = np.arange(9).reshape((3, 3)) + for fig in [fig_test, fig_ref]: + ax = fig.add_subplot() + ax.imshow(t, clip_path=(mpl.path.Path([(0, 0), (0, 1), (1, 0)]), + ax.transData)) + ax.imshow(t, clip_path=(mpl.path.Path([(1, 1), (1, 2), (2, 1)]), + ax.transData)) + fig_ref.suppressComposite = True + + @image_comparison(['rasterize_10dpi'], extensions=['pdf', 'svg'], remove_text=True, style='mpl20') def test_rasterize_dpi():