From 5fdadf560ad455cb7df431a9c7d36ef1bcb49500 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Tue, 18 May 2021 13:43:43 -0700 Subject: [PATCH 1/3] FIX: get proper edgecolor in legends --- lib/matplotlib/legend_handler.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/matplotlib/legend_handler.py b/lib/matplotlib/legend_handler.py index 45fb759d7b23..f470d08c11ef 100644 --- a/lib/matplotlib/legend_handler.py +++ b/lib/matplotlib/legend_handler.py @@ -747,8 +747,7 @@ def get_first(prop_array): return prop_array[0] else: return None - edgecolor = getattr(orig_handle, '_original_edgecolor', - orig_handle.get_edgecolor()) + edgecolor = orig_handle.get_edgecolor() legend_handle.set_edgecolor(first_color(edgecolor)) facecolor = getattr(orig_handle, '_original_facecolor', orig_handle.get_facecolor()) From 1cb7a78f8f01e26aab493454cfecb7a6586fb7d4 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Tue, 18 May 2021 13:56:06 -0700 Subject: [PATCH 2/3] FIX: legend when edgecolor is face --- lib/matplotlib/legend_handler.py | 6 +++++- lib/matplotlib/tests/test_legend.py | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/legend_handler.py b/lib/matplotlib/legend_handler.py index f470d08c11ef..c85979484433 100644 --- a/lib/matplotlib/legend_handler.py +++ b/lib/matplotlib/legend_handler.py @@ -747,7 +747,11 @@ def get_first(prop_array): return prop_array[0] else: return None - edgecolor = orig_handle.get_edgecolor() + edgecolor = getattr(orig_handle, '_original_edgecolor', + orig_handle.get_edgecolor()) + if edgecolor == 'face': + # let get_edgecolor handle this: + edgecolor = orig_handle.get_edgecolor() legend_handle.set_edgecolor(first_color(edgecolor)) facecolor = getattr(orig_handle, '_original_facecolor', orig_handle.get_facecolor()) diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index ff263e86e845..0e645934205e 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -764,3 +764,10 @@ def test_plot_multiple_label_incorrect_length_exception(): label = ['high', 'low', 'medium'] fig, ax = plt.subplots() ax.plot(x, y, label=label) + + +def test_legend_face_edgecolor(): + fig, ax = plt.subplots() + ax.fill_between([0, 1, 2], [1, 2, 3], [2, 3, 4], + facecolor='r', edgecolor='face', label='Fill') + ax.legend() From 5ccdcf162fd683d84832ab068cb6de8714bd5f7f Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Tue, 18 May 2021 14:37:56 -0700 Subject: [PATCH 3/3] FIX: make check simpler --- lib/matplotlib/legend_handler.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/legend_handler.py b/lib/matplotlib/legend_handler.py index c85979484433..c9357ef0fe2c 100644 --- a/lib/matplotlib/legend_handler.py +++ b/lib/matplotlib/legend_handler.py @@ -747,11 +747,9 @@ def get_first(prop_array): return prop_array[0] else: return None - edgecolor = getattr(orig_handle, '_original_edgecolor', - orig_handle.get_edgecolor()) - if edgecolor == 'face': - # let get_edgecolor handle this: - edgecolor = orig_handle.get_edgecolor() + edgecolor = orig_handle.get_edgecolor() + if edgecolor.size == 0: + edgecolor = None legend_handle.set_edgecolor(first_color(edgecolor)) facecolor = getattr(orig_handle, '_original_facecolor', orig_handle.get_facecolor())