8000 Add test for #12773 · matplotlib/matplotlib@46467bb · GitHub
[go: up one dir, main page]

Skip to content

Commit 46467bb

Browse files
committed
Add test for #12773
1 parent 009d952 commit 46467bb

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
@pytest.mark.backend('cairo')
17+
@check_figures_equal(extensions=["png"])
18+
def test_patch_alpha_coloring(fig_test, fig_ref):
19+
"""
20+
Test checks that the patch and collection are rendered with the specified
21+
alpha values in their facecolor and edgecolor.
22+
"""
23+
star = mpath.Path.unit_regular_star(6)
24+
circle = mpath.Path.unit_circle()
25+
# concatenate the star with an internal cutout of the circle
26+
verts = np.concatenate([circle.vertices, star.vertices[::-1]])
27+
codes = np.concatenate([circle.codes, star.codes])
28+
cut_star1 = mpath.Path(verts, codes)
29+
cut_star2 = mpath.Path(verts + 1, codes)
30+
31+
# Reference: two separate patches
32+
ax = fig_ref.subplots()
33+
ax.set_xlim([-1, 2])
34+
ax.set_ylim([-1, 2])
35+
patch = mpatches.PathPatch(cut_star1,
36+
linewidth=5, linestyle=&# B547 39;dashdot',
37+
facecolor=(1, 0, 0, 0.5),
38+
edgecolor=(0, 0, 1, 0.75))
39+
ax.add_patch(patch)
40+
patch = mpatches.PathPatch(cut_star2,
41+
linewidth=5, linestyle='dashdot',
42+
facecolor=(1, 0, 0, 0.5),
43+
edgecolor=(0, 0, 1, 0.75))
44+
ax.add_patch(patch)
45+
plt.savefig('patch_alpha_coloring.png')
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)
56+
57+
plt.savefig('patch_alpha_coloring_test.png')
58+

0 commit comments

Comments
 (0)
0