Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eba3d76

Browse files
committed
Fixed hatching in patches
1 parent a218d5c commit eba3d76

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

lib/matplotlib/collections.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,10 +1846,13 @@ def __init__(self, patches, *, match_original=False, **kwargs):
18461846
a heterogeneous assortment of different patch types.
18471847
18481848
match_original : bool, default: False
1849-
If True, use the colors and linewidths of the original
1850-
patches. If False, new colors may be assigned by
1849+
If True, use the colors, linewidths, linestyles
1850+
and the hatch of the original patches.
1851+
If False, new colors may be assigned by
18511852
providing the standard collection arguments, facecolor,
18521853
edgecolor, linewidths, norm or cmap.
1854+
Also, all hatches will be set to the first patch's hatch,
1855+
regardless of the hatch set in the original patches.
18531856
18541857
**kwargs
18551858
All other parameters are forwarded to `.Collection`.
@@ -1867,17 +1870,20 @@ def __init__(self, patches, *, match_original=False, **kwargs):
18671870
"""
18681871

18691872
if match_original:
1870-
def determine_facecolor(patch):
1871-
if patch.get_fill():
1872-
return patch.get_facecolor()
1873-
return [0, 0, 0, 0]
1874-
1875-
kwargs['facecolors'] = [determine_facecolor(p) for p in patches]
1876-
kwargs['edgecolors'] = [p.get_edgecolor() for p in patches]
1873+
kwargs['facecolors'] = [p.get_facecolor() for p in patches]
18771874
kwargs['linewidths'] = [p.get_linewidth() for p in patches]
18781875
kwargs['linestyles'] = [p.get_linestyle() for p in patches]
18791876
kwargs['antialiaseds'] = [p.get_antialiased() for p in patches]
18801877

1878+
# Edgecolors are handled separately because are defaulted to None
1879+
# and the Hatch colors depend on them.
1880+
if any(p._original_edgecolor is not None for p in patches):
1881+
kwargs["edgecolors"] = [p.get_edgecolor() for p in patches]
1882+
1883+
# Using the hatch of only the first patch
1884+
if patches:
1885+
kwargs['hatch'] = patches[0].get_hatch()
1886+
18811887
super().__init__(**kwargs)
18821888

18831889
self.set_paths(patches)

0 commit comments

Comments
 (0)