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

Skip to content

Commit 871019a

Browse files
r3ksteImpaler343
authored andcommitted
added logic to inherit hatchcolor from edgecolor
1 parent e89113e commit 871019a

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

lib/matplotlib/collections.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ def __init__(self, *,
168168
self._linewidths = [0]
169169

170170
self._gapcolor = None # Currently only used by LineCollection.
171+
self._original_edgecolor = None
172+
self._original_hatchcolor = None
171173

172174
# Flags set by _set_mappable_flags: are colors from mapping an array?
173175
self._face_is_mapped = None
@@ -810,9 +812,17 @@ def _set_edgecolor(self, c):
810812
c = 'none'
811813
if cbook._str_lower_equal(c, 'face'):
812814
self._edgecolors = 'face'
815+
if self._original_hatchcolor is None:
816+
self._set_hatchcolor('black')
813817
self.stale = True
814818
return
815819
self._edgecolors = mcolors.to_rgba_array(c, self._alpha)
820+
if self._original_hatchcolor is None:
821+
if isinstance(c, str) and c == 'none':
822+
self._set_hatchcolor('black')
823+
else:
824+
self._hatchcolors = self._edgecolors
825+
self._hatch_color = self._hatchcolors[0]
816826
self.stale = True
817827

818828
def set_edgecolor(self, c):
@@ -836,7 +846,18 @@ def set_edgecolor(self, c):
836846
def _set_hatchcolor(self, c):
837847
c = mpl._val_or_rc(c, "hatch.color")
838848
if c == "inherit":
839-
c = mpl.rcParams["patch.edgecolor"]
849+
if self._original_edgecolor is not None:
850+
c = self._original_edgecolor
851+
else:
852+
c = mpl.rcParams["patch.edgecolor"]
853+
854+
if not isinstance(c, str):
855+
if len(c) == 0:
856+
c = "black"
857+
else:
858+
if c in ('none', 'face'):
859+
c = "black"
860+
840861
self._hatchcolors = mcolors.to_rgba_array(c, self._alpha)
841862
self._hatch_color = self._hatchcolors[0]
842863
self.stale = True

lib/matplotlib/mpl-data/stylelib/classic.mplstyle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ patch.force_edgecolor : True
3636
patch.edgecolor : k
3737
patch.antialiased : True # render patches in antialiased (no jaggies)
3838

39-
hatch.color : k
39+
hatch.color : inherit
4040
hatch.linewidth : 1.0
4141

4242
hist.bins : 10

lib/matplotlib/patches.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ def __init__(self, *,
7272
if joinstyle is None:
7373
joinstyle = JoinStyle.miter
7474

75-
hatchcolor = mpl._val_or_rc(hatchcolor, "hatch.color")
76-
if hatchcolor == 'inherit':
77-
hatchcolor = mpl.rcParams["patch.edgecolor"]
75+
self._original_edgecolor = None
76+
self._original_hatchcolor = None
7877

7978
self._fill = bool(fill) # needed for set_facecolor call
8079
if color is not None:
@@ -373,6 +372,8 @@ def _set_edgecolor(self, color):
373372
color = 'none'
374373

375374
self._edgecolor = colors.to_rgba(color, self._alpha)
375+
if self._original_hatchcolor is None:
376+
self._hatch_color = self._edgecolor
376377
self.stale = True
377378

378379
def set_edgecolor(self, color):
@@ -422,6 +423,12 @@ def set_color(self, c):
422423
self.set_facecolor(c)
423424

424425
def _set_hatchcolor(self, color):
426+
color = mpl._val_or_rc(color, "hatch.color")
427+
if color == 'inherit':
428+
if self._original_edgecolor is not None:
429+
color = self._original_edgecolor
430+
else:
431+
color = mpl.rcParams['patch.edgecolor']
425432
self._hatch_color = colors.to_rgba(color, self._alpha)
426433
self.stale = True
427434

0 commit comments

Comments
 (0)