8000 Made it so that PatchCollection uses the hatch of the patch in the co… · matplotlib/matplotlib@43f16a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 43f16a0

Browse files
committed
Made it so that PatchCollection uses the hatch of the patch in the collection.
PatchCollection will currently ignore hatches of the provided patches, only allowing a hatch passed as a keyword into the constructor. If match_original is true, we now keep the hatch of the first patch provided in the collection. Additionally, the hatchcolor is determined by the edge color, so we will only pass the edgecolors of the patches to the Collection if the edgecolor is not blank - its default color of [0, 0, 0, 0]. This ensures that the hatch will use its default of black in the case where no edgecolor of the patches was ever set.
1 parent 8c94a22 commit 43f16a0

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,9 +1808,10 @@ def __init__(self, patches, match_original=False, **kwargs):
18081808
18091809
*match_original*
18101810
If True, use the colors and linewidths of the original
1811-
patches. If False, new colors may be assigned by
1812-
providing the standard collection arguments, facecolor,
1813-
edgecolor, linewidths, norm or cmap.
1811+
patches. Also use the hatch of the first patch provided.
1812+
If False, new colors may be assigned by providing the
1813+
standard collection arguments, facecolor, edgecolor,
1814+
linewidths, norm or cmap.
18141815
18151816
If any of *edgecolors*, *facecolors*, *linewidths*, *antialiaseds* are
18161817
None, they default to their `.rcParams` patch setting, in sequence
@@ -1827,12 +1828,20 @@ def determine_facecolor(patch):
18271828
if patch.get_fill():
18281829
return patch.get_facecolor()
18291830
return [0, 0, 0, 0]
1830-
1831+
def is_default(c):
1832+
return mcolors.same_color([0, 0, 0, 0], c)
18311833
kwargs['facecolors'] = [determine_facecolor(p) for p in patches]
1832-
kwargs['edgecolors'] = [p.get_edgecolor() for p in patches]
1834+
edgecolors = [p.get_edgecolor() for p in patches]
1835+
# Since the hatch color is updated when the edge color
1836+
# is updated, we will ignore the edge color if it is blank (the
1837+
# default of [0, 0, 0, 0]).
1838+
if not all(is_default(c) for c in edgecolors):
1839+
kwargs['edgecolors'] = edgecolors
18331840
kwargs['linewidths'] = [p.get_linewidth() for p in patches]
18341841
kwargs['linestyles'] = [p.get_linestyle() for p in patches]
18351842
kwargs['antialiaseds'] = [p.get_antialiased() for p in patches]
1843+
if patches:
1844+
kwargs['hatch'] = patches[0].get_hatch()
18361845

18371846
super().__init__(**kwargs)
18381847

0 commit comments

Comments
 (0)
0