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

Skip to content

Commit 4c46381

Browse files
committed
Use original face/edge color to create Poly legend.
This ensures that additional settings like hatch colours get set up properly.
1 parent f92e79c commit 4c46381

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

lib/matplotlib/legend_handler.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ class HandlerPolyCollection(HandlerBase):
592592
"""
593593
def _update_prop(self, legend_handle, orig_handle):
594594
def first_color(colors):
595+
if colors is None:
596+
return None
595597
colors = mcolors.to_rgba_array(colors)
596598
if len(colors):
597599
return colors[0]
@@ -602,8 +604,12 @@ def get_first(prop_array):
602604
return prop_array[0]
603605
else:
604606
return None
605-
legend_handle.set_edgecolor(first_color(orig_handle.get_edgecolor()))
606-
legend_handle.set_facecolor(first_color(orig_handle.get_facecolor()))
607+
edgecolor = getattr(orig_handle, '_original_edgecolor',
608+
orig_handle.get_edgecolor())
609+
legend_handle.set_edgecolor(first_color(edgecolor))
610+
facecolor = getattr(orig_handle, '_original_facecolor',
611+
orig_handle.get_facecolor())
612+
legend_handle.set_facecolor(first_color(facecolor))
607613
legend_handle.set_fill(orig_handle.get_fill())
608614
legend_handle.set_hatch(orig_handle.get_hatch())
609615
legend_handle.set_linewidth(get_first(orig_handle.get_linewidths()))

0 commit comments

Comments
 (0)