Skip to content

Don't composite path-clipped image; forward suppressComposite as needed. #19375

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
May 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/api/next_api_changes/behavior/19375-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``Figure.suppressComposite`` now also controls compositing of Axes images
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 changes: 2 additions & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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.
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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():
Expand Down