Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8272e7b

Browse filesBrowse files
johtimhoffm
authored andcommitted
Cairo backend: Fix alpha render of collections (#12774)
Remove RendererCairo.draw_path_collection as it made some wrong assumptions in the grouped draw optimization. Add test for the cairo backend to check rendering of path collections. Fixes #12773
1 parent 585644b commit 8272e7b
Copy full SHA for 8272e7b

File tree

Expand file treeCollapse file tree

2 files changed

+55
-51
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+55
-51
lines changed

‎lib/matplotlib/backends/backend_cairo.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_cairo.py
-51Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -286,57 +286,6 @@ def draw_markers(self, gc, marker_path, marker_trans, path, transform,
286286
self._fill_and_stroke(
287287
ctx, rgbFace, gc.get_alpha(), gc.get_forced_alpha())
288288

289-
def draw_path_collection(
290-
self, gc, master_transform, paths, all_transforms, offsets,
291-
offsetTrans, facecolors, edgecolors, linewidths, linestyles,
292-
antialiaseds, urls, offset_position):
293-
294-
path_ids = [
295-
(path, Affine2D(transform))
296-
for path, transform in self._iter_collection_raw_paths(
297-
master_transform, paths, all_transforms)]
298-
299-
reuse_key = None
300-
grouped_draw = []
301-
302-
def _draw_paths():
303-
if not grouped_draw:
304-
return
305-
gc_vars, rgb_fc = reuse_key
306-
gc = copy.copy(gc0)
307-
# We actually need to call the setters to reset the internal state.
308-
vars(gc).update(gc_vars)
309-
for k, v in gc_vars.items():
310-
if k == "_linestyle": # Deprecated, no effect.
311-
continue
312-
try:
313-
getattr(gc, "set" + k)(v)
314-
except (AttributeError, TypeError) as e:
315-
pass
316-
gc.ctx.new_path()
317-
paths, transforms = zip(*grouped_draw)
318-
grouped_draw.clear()
319-
_append_paths(gc.ctx, paths, transforms)
320-
self._fill_and_stroke(
321-
gc.ctx, rgb_fc, gc.get_alpha(), gc.get_forced_alpha())
322-
323-
for xo, yo, path_id, gc0, rgb_fc in self._iter_collection(
324-
gc, master_transform, all_transforms, path_ids, offsets,
325-
offsetTrans, facecolors, edgecolors, linewidths, linestyles,
326-
antialiaseds, urls, offset_position):
327-
path, transform = path_id
328-
transform = (Affine2D(transform.get_matrix())
329-
.translate(xo, yo - self.height).scale(1, -1))
330-
# rgb_fc could be a ndarray, for which equality is elementwise.
331-
new_key = vars(gc0), tuple(rgb_fc) if rgb_fc is not None else None
332-
if new_key == reuse_key:
333-
grouped_draw.append((path, transform))
334-
else:
335-
_draw_paths()
336-
grouped_draw.append((path, transform))
337-
reuse_key = new_key
338-
_draw_paths()
339-
340289
def draw_image(self, gc, x, y, im):
341290
im = cbook._unmultiplied_rgba8888_to_premultiplied_argb32(im[::-1])
342291
surface = cairo.ImageSurface.create_for_data(
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import numpy as np
2+
from io import BytesIO
3+
import os
4+
import tempfile
5+
import warnings
6+
import xml.parsers.expat
7+
8+
import pytest
9+
10+
import matplotlib.pyplot as plt
11+
from matplotlib.testing.decorators import check_figures_equal
12+
import matplotlib
13+
from matplotlib import (
14+
collections as mcollections, patches as mpatches, path as mpath)
15+
16+
17+
@pytest.mark.backend('cairo')
18+
@check_figures_equal(extensions=["png"])
19+
def test_patch_alpha_coloring(fig_test, fig_ref):
20+
"""
21+
Test checks that the patch and collection are rendered with the specified
22+
alpha values in their facecolor and edgecolor.
23+
"""
24+
star = mpath.Path.unit_regular_star(6)
25+
circle = mpath.Path.unit_circle()
26+
# concatenate the star with an internal cutout of the circle
27+
verts = np.concatenate([circle.vertices, star.vertices[::-1]])
28+
codes = np.concatenate([circle.codes, star.codes])
29+
cut_star1 = mpath.Path(verts, codes)
30+
cut_star2 = mpath.Path(verts + 1, codes)
31+
32+
# Reference: two separate patches
33+
ax = fig_ref.subplots()
34+
ax.set_xlim([-1, 2])
35+
ax.set_ylim([-1, 2])
36+
patch = mpatches.PathPatch(cut_star1,
37+
linewidth=5, linestyle='dashdot',
38+
facecolor=(1, 0, 0, 0.5),
39+
edgecolor=(0, 0, 1, 0.75))
40+
ax.add_patch(patch)
41+
patch = mpatches.PathPatch(cut_star2,
42+
linewidth=5, linestyle='dashdot',
43+
facecolor=(1, 0, 0, 0.5),
44+
edgecolor=(0, 0, 1, 0.75))
45+
ax.add_patch(patch)
46+
47+
# Test: path collection
48+
ax = fig_test.subplots()
49+
ax.set_xlim([-1, 2])
50+
ax.set_ylim([-1, 2])
51+
col = mcollections.PathCollection([cut_star1, cut_star2],
52+
linewidth=5, linestyles='dashdot',
53+
facecolor=(1, 0, 0, 0.5),
54+
edgecolor=(0, 0, 1, 0.75))
55+
ax.add_collection(col)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.