Skip to content

Commit 0210a5b

Browse files
committed
Don't composite path-clipped image; forward suppressComposite as needed.
1 parent 408b1ab commit 0210a5b

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``Figure.suppressComposite`` now also controls compositing of Axes images
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,8 @@ def draw(self, renderer=None, inframe=False):
29212921
a.draw(renderer)
29222922
renderer.stop_rasterizing()
29232923

2924-
mimage._draw_list_compositing_images(renderer, self, artists)
2924+
mimage._draw_list_compositing_images(
2925+
renderer, self, artists, self.figure.suppressComposite)
29252926

29262927
renderer.close_group('axes')
29272928
self.stale = False

lib/matplotlib/figure.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,8 @@ def draw(self, renderer):
20082008
try:
20092009
renderer.open_group('subfigure', gid=self.get_gid())
20102010
self.patch.draw(renderer)
2011-
mimage._draw_list_compositing_images(renderer, self, artists)
2011+
mimage._draw_list_compositing_images(
2012+
renderer, self, artists, self.figure.suppressComposite)
20122013
for sfig in self.subfigs:
20132014
sfig.draw(renderer)
20142015
renderer.close_group('subfigure')
@@ -2032,7 +2033,7 @@ class Figure(FigureBase):
20322033
The `.Rectangle` instance representing the figure background patch.
20332034
20342035
suppressComposite
2035-
For multiple figure images, the figure will make composite images
2036+
For multiple images, the figure will make composite images
20362037
depending on the renderer option_image_nocomposite function. If
20372038
*suppressComposite* is a boolean, this will override the renderer.
20382039
"""

lib/matplotlib/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def flush_images():
150150

151151
for a in artists:
152152
if (isinstance(a, _ImageBase) and a.can_composite() and
153-
a.get_clip_on()):
153+
a.get_clip_on() and not a.get_clip_path()):
154154
image_group.append(a)
155155
else:
156156
flush_images()

lib/matplotlib/tests/test_image.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from numpy.testing import assert_array_equal
1212
from PIL import Image
1313

14+
import matplotlib as mpl
1415
from matplotlib import (
1516
colors, image as mimage, patches, pyplot as plt, style, rcParams)
1617
from matplotlib.image import (AxesImage, BboxImage, FigureImage,
@@ -506,6 +507,19 @@ def test_image_composite_alpha():
506507
ax.set_ylim([5, 0])
507508

508509

510+
@check_figures_equal(extensions=["pdf"])
511+
def test_clip_path_disables_compositing(fig_test, fig_ref):
512+
t = np.arange(9).reshape((3, 3))
513+
for fig in [fig_test, fig_ref]:
514+
ax = fig.add_subplot()
515+
ax.imshow(t, clip_path=(mpl.path.Path([(0, 0), (0, 1), (1, 0)]),
516+
ax.transData))
517+
ax.imshow(t, clip_path=(mpl.path.Path([(1, 1), (1, 2), (2, 1)]),
518+
ax.transData))
519+
fig_ref.suppressComposite = True
520+
521+
522+
509523
@image_comparison(['rasterize_10dpi'],
510524
extensions=['pdf', 'svg'], remove_text=True, style='mpl20')
511525
def test_rasterize_dpi():

0 commit comments

Comments
 (0)