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

Skip to content

Commit bdb3679

Browse files
committed
FIX: Restore hatch color tracking edge color
1 parent 5a895da commit bdb3679

14 files changed

+459
-101
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,8 @@ def copy_properties(self, gc):
817817
self._linewidth = gc._linewidth
818818
self._rgb = gc._rgb
819819
self._hatch = gc._hatch
820+
self._hatch_color = gc._hatch_color
821+
self._hatch_linewidth = gc._hatch_linewidth
820822
self._url = gc._url
821823
self._gid = gc._gid
822824
self._snap = gc._snap
@@ -1109,8 +1111,18 @@ def get_hatch_color(self):
11091111
"""
11101112
Gets the color to use for hatching.
11111113
"""
1114+
if self._hatch_color is None:
1115+
return colors.to_rgba(rcParams['hatch.color'])
11121116
return self._hatch_color
11131117

1118+
def set_hatch_color(self, hatch_color):
1119+
"""
1120+
Gets the color to use for hatching.
1121+
"""
1122+
if hatch_color is None:
1123+
raise ValueError()
1124+
self._hatch_color = hatch_color
1125+
11141126
def get_hatch_linewidth(self):
11151127
"""
11161128
Gets the linewidth to use for hatching.

lib/matplotlib/backends/backend_pdf.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,14 +2210,14 @@ def alpha_cmd(self, alpha, forced, effective_alphas):
22102210
name = self.file.alphaState(effective_alphas)
22112211
return [name, Op.setgstate]
22122212

2213-
def hatch_cmd(self, hatch):
2213+
def hatch_cmd(self, hatch, hatch_color):
22142214
if not hatch:
22152215
if self._fillcolor is not None:
22162216
return self.fillcolor_cmd(self._fillcolor)
22172217
else:
22182218
return [Name('DeviceRGB'), Op.setcolorspace_nonstroke]
22192219
else:
2220-
hatch_style = (self._hatch_color, self._fillcolor, hatch)
2220+
hatch_style = (hatch_color, self._fillcolor, hatch)
22212221
name = self.file.hatchPattern(hatch_style)
22222222
return [Name('Pattern'), Op.setcolorspace_nonstroke,
22232223
name, Op.setcolor_nonstroke]
@@ -2281,7 +2281,8 @@ def clip_cmd(self, cliprect, clippath):
22812281
(('_linewidth',), linewidth_cmd),
22822282
(('_dashes',), dash_cmd),
22832283
(('_rgb',), rgb_cmd),
2284-
(('_hatch',), hatch_cmd), # must come after fillcolor and rgb
2284+
# must come after fillcolor and rgb
2285+
(('_hatch', '_hatch_color'), hatch_cmd),
22852286
)
22862287

22872288
# TODO: _linestyle

lib/matplotlib/collections.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def __init__(self,
136136
self._linewidths = [0]
137137
self._is_filled = True # May be modified by set_facecolor().
138138

139+
self._hatch_color = None
139140
self.set_facecolor(facecolors)
140141
self.set_edgecolor(edgecolors)
141142
self.set_linewidth(linewidths)
@@ -293,6 +294,14 @@ def draw(self, renderer):
293294

294295
if self._hatch:
295296
gc.set_hatch(self._hatch)
297+
if self._hatch_color is not None:
298+
try:
299+
gc.set_hatch_color(self._hatch_color)
300+
except AttributeError:
301+
# if we end up with a GC that does not have this method
302+
import warnings
303+
warnings.warn("Your backend does not have support for "
304+
"setting the hatch color.")
296305

297306
if self.get_sketch_params() is not None:
298307
gc.set_sketch_params(*self.get_sketch_params())
@@ -690,12 +699,15 @@ def get_edgecolor(self):
690699
get_edgecolors = get_edgecolor
691700

692701
def _set_edgecolor(self, c):
702+
set_hatch_color = True
693703
if c is None:
694704
if (mpl.rcParams['patch.force_edgecolor'] or
695705
not self._is_filled or self._edge_default):
696706
c = mpl.rcParams['patch.edgecolor']
697707
else:
698708
c = 'none'
709+
set_hatch_color = False
710+
699711
self._is_stroked = True
700712
try:
701713
if c.lower() == 'none':
@@ -710,6 +722,8 @@ def _set_edgecolor(self, c):
710722
except AttributeError:
711723
pass
712724
self._edgecolors = mcolors.to_rgba_array(c, self._alpha)
725+
if set_hatch_color and len(self._edgecolors):
726+
self._hatch_color = tuple(self._edgecolors[0])
713727
self.stale = True
714728

715729
def set_edgecolor(self, c):

lib/matplotlib/patches.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def __init__(self,
113113
if antialiased is None:
114114
antialiased = mpl.rcParams['patch.antialiased']
115115

116+
self._hatch_color = None
116117
self._fill = True # needed for set_facecolor call
117118
if color is not None:
118119
if (edgecolor is not None or facecolor is not None):
@@ -288,13 +289,18 @@ def set_aa(self, aa):
288289
return self.set_antialiased(aa)
289290

290291
def _set_edgecolor(self, color):
292+
set_hatch_color = True
291293
if color is None:
292294
if (mpl.rcParams['patch.force_edgecolor'] or
293295
not self._fill or self._edge_default):
294296
color = mpl.rcParams['patch.edgecolor']
295297
else:
296298
color = 'none'
299+
set_hatch_color = False
300+
297301
self._edgecolor = colors.to_rgba(color, self._alpha)
302+
if set_hatch_color:
303+
self._hatch_color = self._edgecolor
298304
self.stale = True
299305

300306
def set_edgecolor(self, color):
@@ -545,6 +551,14 @@ def draw(self, renderer):
545551

546552
if self._hatch:
547553
gc.set_hatch(self._hatch)
554+
if self._hatch_color is not None:
555+
try:
556+
gc.set_hatch_color(self._hatch_color)
557+
except AttributeError:
558+
# if we end up with a GC that does not have this method
559+
import warnings
560+
warnings.warn("Your backend does not have support for "
561+
"setting the hatch color.")
548562

549563
if self.get_sketch_params() is not None:
550564
gc.set_sketch_params(*self.get_sketch_params())
@@ -4286,6 +4300,14 @@ def draw(self, renderer):
42864300

42874301
if self._hatch:
42884302
gc.set_hatch(self._hatch)
4303+
if self._hatch_color is not None:
4304+
try:
4305+
gc.set_hatch_color(self._hatch_color)
4306+
except AttributeError:
4307+
# if we end up with a GC that does not have this method
4308+
import warnings
4309+
warnings.warn("Your backend does not have support for "
4310+
"setting the hatch color.")
42894311

42904312
if self.get_sketch_params() is not None:
42914313
gc.set_sketch_params(*self.get_sketch_params())
Binary file not shown.

0 commit comments

Comments
 (0)