diff --git a/lib/matplotlib/backends/backend_cairo.py b/lib/matplotlib/backends/backend_cairo.py index 39f36f3646f8..7d8166451a6c 100644 --- a/lib/matplotlib/backends/backend_cairo.py +++ b/lib/matplotlib/backends/backend_cairo.py @@ -286,57 +286,6 @@ def draw_markers(self, gc, marker_path, marker_trans, path, transform, self._fill_and_stroke( ctx, rgbFace, gc.get_alpha(), gc.get_forced_alpha()) - def draw_path_collection( - self, gc, master_transform, paths, all_transforms, offsets, - offsetTrans, facecolors, edgecolors, linewidths, linestyles, - antialiaseds, urls, offset_position): - - path_ids = [ - (path, Affine2D(transform)) - for path, transform in self._iter_collection_raw_paths( - master_transform, paths, all_transforms)] - - reuse_key = None - grouped_draw = [] - - def _draw_paths(): - if not grouped_draw: - return - gc_vars, rgb_fc = reuse_key - gc = copy.copy(gc0) - # We actually need to call the setters to reset the internal state. - vars(gc).update(gc_vars) - for k, v in gc_vars.items(): - if k == "_linestyle": # Deprecated, no effect. - continue - try: - getattr(gc, "set" + k)(v) - except (AttributeError, TypeError) as e: - pass - gc.ctx.new_path() - paths, transforms = zip(*grouped_draw) - grouped_draw.clear() - _append_paths(gc.ctx, paths, transforms) - self._fill_and_stroke( - gc.ctx, rgb_fc, gc.get_alpha(), gc.get_forced_alpha()) - - for xo, yo, path_id, gc0, rgb_fc in self._iter_collection( - gc, master_transform, all_transforms, path_ids, offsets, - offsetTrans, facecolors, edgecolors, linewidths, linestyles, - antialiaseds, urls, offset_position): - path, transform = path_id - transform = (Affine2D(transform.get_matrix()) - .translate(xo, yo - self.height).scale(1, -1)) - # rgb_fc could be a ndarray, for which equality is elementwise. - new_key = vars(gc0), tuple(rgb_fc) if rgb_fc is not None else None - if new_key == reuse_key: - grouped_draw.append((path, transform)) - else: - _draw_paths() - grouped_draw.append((path, transform)) - reuse_key = new_key - _draw_paths() - def draw_image(self, gc, x, y, im): im = cbook._unmultiplied_rgba8888_to_premultiplied_argb32(im[::-1]) surface = cairo.ImageSurface.create_for_data( diff --git a/lib/matplotlib/tests/test_backend_cairo.py b/lib/matplotlib/tests/test_backend_cairo.py new file mode 100644 index 000000000000..d758ca99e57d --- /dev/null +++ b/lib/matplotlib/tests/test_backend_cairo.py @@ -0,0 +1,55 @@ +import numpy as np +from io import BytesIO +import os +import tempfile +import warnings +import xml.parsers.expat + +import pytest + +import matplotlib.pyplot as plt +from matplotlib.testing.decorators import check_figures_equal +import matplotlib +from matplotlib import ( + collections as mcollections, patches as mpatches, path as mpath) + + +@pytest.mark.backend('cairo') +@check_figures_equal(extensions=["png"]) +def test_patch_alpha_coloring(fig_test, fig_ref): + """ + Test checks that the patch and collection are rendered with the specified + alpha values in their facecolor and edgecolor. + """ + star = mpath.Path.unit_regular_star(6) + circle = mpath.Path.unit_circle() + # concatenate the star with an internal cutout of the circle + verts = np.concatenate([circle.vertices, star.vertices[::-1]]) + codes = np.concatenate([circle.codes, star.codes]) + cut_star1 = mpath.Path(verts, codes) + cut_star2 = mpath.Path(verts + 1, codes) + + # Reference: two separate patches + ax = fig_ref.subplots() + ax.set_xlim([-1, 2]) + ax.set_ylim([-1, 2]) + patch = mpatches.PathPatch(cut_star1, + linewidth=5, linestyle='dashdot', + facecolor=(1, 0, 0, 0.5), + edgecolor=(0, 0, 1, 0.75)) + ax.add_patch(patch) + patch = mpatches.PathPatch(cut_star2, + linewidth=5, linestyle='dashdot', + facecolor=(1, 0, 0, 0.5), + edgecolor=(0, 0, 1, 0.75)) + ax.add_patch(patch) + + # Test: path collection + ax = fig_test.subplots() + ax.set_xlim([-1, 2]) + ax.set_ylim([-1, 2]) + col = mcollections.PathCollection([cut_star1, cut_star2], + linewidth=5, linestyles='dashdot', + facecolor=(1, 0, 0, 0.5), + edgecolor=(0, 0, 1, 0.75)) + ax.add_collection(col)