From 597bfffa68408fd8fc07c935200c59166398a8bc Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Tue, 7 Jan 2025 10:24:36 -0500 Subject: [PATCH 1/3] BUG: Fix regression with set_hatchcolor --- lib/matplotlib/patches.py | 2 +- lib/matplotlib/tests/test_patches.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 54a0908da737..f7eb910d8dc0 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -425,7 +425,7 @@ def set_color(self, c): def _set_hatchcolor(self, color): color = mpl._val_or_rc(color, 'hatch.color') - if color == 'edge': + if isinstance(color, str) and color == 'edge': self._hatch_color = 'edge' else: self._hatch_color = colors.to_rgba(color, self._alpha) diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index e76c6f6ae874..78fad6a07ec8 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -1023,6 +1023,9 @@ def test_patch_hatchcolor_inherit_logic(): rect.set_edgecolor('green') assert mcolors.same_color(rect.get_hatchcolor(), 'purple') + # Smoke test for setting with numpy array + rect.set_hatchcolor(np.ones(3)) + def test_patch_hatchcolor_fallback_logic(): # Test for when hatchcolor parameter is passed From 5ca210a6b7f712b8e0f876fb58c21e299f96e83d Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Tue, 7 Jan 2025 10:48:54 -0500 Subject: [PATCH 2/3] Update lib/matplotlib/patches.py Co-authored-by: Greg Lucas --- lib/matplotlib/patches.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index f7eb910d8dc0..5cab1a18bf0c 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -425,7 +425,7 @@ def set_color(self, c): def _set_hatchcolor(self, color): color = mpl._val_or_rc(color, 'hatch.color') - if isinstance(color, str) and color == 'edge': + if cbook._str_equal(color, 'edge'): self._hatch_color = 'edge' else: self._hatch_color = colors.to_rgba(color, self._alpha) From e3e94ea1d425b0192d9163433c2b01c2e255a4ae Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Tue, 7 Jan 2025 10:49:43 -0500 Subject: [PATCH 3/3] FIX: Remove --- lib/matplotlib/patches.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 5cab1a18bf0c..2cc09a5931f6 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -439,8 +439,6 @@ def set_hatchcolor(self, color): ---------- color : :mpltype:`color` or 'edge' or None """ - if cbook._str_equal(color, 'edge'): - color = 'edge' self._original_hatchcolor = color self._set_hatchcolor(color)