diff options
author | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2017-05-04 22:37:58 -0400 |
---|---|---|
committer | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2017-05-04 22:37:58 -0400 |
commit | 4c463813a3c0b56e07fb10b6ff4704d6e5efde8c (patch) | |
tree | ca9399b0a5e410d84f24520b5e7c363933d76448 | |
parent | f92e79cd2454f4c16542375d35445ddbfdbc5939 (diff) |
Use original face/edge color to create Poly legend.
This ensures that additional settings like hatch colours get set up
properly.
-rw-r--r-- | lib/matplotlib/legend_handler.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/matplotlib/legend_handler.py b/lib/matplotlib/legend_handler.py index 1cc81fa04..79661119d 100644 --- a/lib/matplotlib/legend_handler.py +++ b/lib/matplotlib/legend_handler.py @@ -592,6 +592,8 @@ class HandlerPolyCollection(HandlerBase): """ def _update_prop(self, legend_handle, orig_handle): def first_color(colors): + if colors is None: + return None colors = mcolors.to_rgba_array(colors) if len(colors): return colors[0] @@ -602,8 +604,12 @@ class HandlerPolyCollection(HandlerBase): return prop_array[0] else: return None - legend_handle.set_edgecolor(first_color(orig_handle.get_edgecolor())) - legend_handle.set_facecolor(first_color(orig_handle.get_facecolor())) + edgecolor = getattr(orig_handle, '_original_edgecolor', + orig_handle.get_edgecolor()) + legend_handle.set_edgecolor(first_color(edgecolor)) + facecolor = getattr(orig_handle, '_original_facecolor', + orig_handle.get_facecolor()) + legend_handle.set_facecolor(first_color(facecolor)) legend_handle.set_fill(orig_handle.get_fill()) legend_handle.set_hatch(orig_handle.get_hatch()) legend_handle.set_linewidth(get_first(orig_handle.get_linewidths())) |