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

Skip to content

Commit d40d1fa

Browse files
committed
Added Workaround to check if hatchcolor is set by user
1 parent 1aad49d commit d40d1fa

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/matplotlib/patches.py

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

75+
self.set_hatch_color = False
7576
self._fill = bool(fill) # needed for set_facecolor call
7677
if color is not None:
7778
if edgecolor is not None or facecolor is not None:
@@ -313,17 +314,17 @@ def set_antialiased(self, aa):
313314
self.stale = True
314315

315316
def _set_edgecolor(self, color):
316-
set_hatch_color = True
317+
set_hatch_color_from_edgecolor = True
317318
if color is None:
318319
if (mpl.rcParams['patch.force_edgecolor'] or
319320
not self._fill or self._edge_default):
320321
color = mpl.rcParams['patch.edgecolor']
321322
else:
322323
color = 'none'
323-
set_hatch_color = False
324+
set_hatch_color_from_edgecolor = False
324325

325326
self._edgecolor = colors.to_rgba(color, self._alpha)
326-
if set_hatch_color:
327+
if set_hatch_color_from_edgecolor and (not self.set_hatch_color):
327328
self._hatch_color = self._edgecolor
328329
self.stale = True
329330

@@ -374,7 +375,9 @@ def set_color(self, c):
374375
self.set_edgecolor(c)
375376

376377
def _set_hatchcolor(self, color):
378+
self.set_hatch_color = True
377379
if color is None:
380+
self.set_hatch_color = False
378381
color = mpl.rcParams['hatch.color']
379382
alpha = self._alpha if self._fill else 0
380383
self._hatch_color = colors.to_rgba(color, alpha)

lib/matplotlib/tests/test_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8859,7 +8859,7 @@ def test_bar_hatchcolor_with_facecolor_and_edgecolor(fig_test, fig_ref):
88598859

88608860
ax1 = fig_test.subplots()
88618861
ax1.bar(x, y, hatch="////", facecolor=(0, 0, 0, 0),
8862-
edgecolor="black", hatchcolor="red")
8862+
hatchcolor="red", edgecolor="black")
88638863

88648864
ax2 = fig_ref.subplots()
88658865
ax2.bar(x, y, hatch="////", facecolor=(0, 0, 0, 0),
@@ -8871,7 +8871,7 @@ def test_bar_hatchcolor_with_facecolor(fig_test, fig_ref):
88718871
x = [6, 7, 8, 9]
88728872
y = [2, 4, 7, 3]
88738873
ax1 = fig_test.subplots()
8874-
ax1.bar(x, y, hatch="////", facecolor=(0, 0, 0, 0), hatchcolor="green")
8874+
ax1.bar(x, y, hatch="////", hatchcolor="green", facecolor=(0, 0, 0, 0))
88758875

88768876
ax2 = fig_ref.subplots()
88778877
ax2.bar(x, y, hatch="////", facecolor=(0, 0, 0, 0), hatchcolor="green")

0 commit comments

Comments
 (0)