@@ -35,7 +35,8 @@ def legend_artist(self, legend, orig_handle, fontsize, handlebox):
3535from matplotlib .lines import Line2D
3636from matplotlib .patches import Rectangle
3737import matplotlib .collections as mcoll
38-
38+ import matplotlib .colors as mcolors
39+ import matplotlib .artist as artist
3940
4041def update_from_first_child (tgt , src ):
4142 tgt .update_from (src .get_children ()[0 ])
@@ -581,3 +582,39 @@ def create_artists(self, legend, orig_handle,
581582 a_list .extend (_a_list )
582583
583584 return a_list
585+
586+
587+ class HandlerPolyCollection (HandlerBase ):
588+ """
589+ Handler for PolyCollection used in fill_between and stackplot.
590+ """
591+ def _update_prop (self , legend_handle , orig_handle ):
592+ def first_color (colors ):
593+ colors = mcolors .colorConverter .to_rgba_array (colors )
594+ if len (colors ):
595+ return colors [0 ]
596+ else :
597+ return "none"
598+ def get_first (prop_array ):
599+ if len (prop_array ):
600+ return prop_array [0 ]
601+ else :
602+ return None
603+ #artist.Artist.update_from(legend_handle, orig_handle)
604+ legend_handle .set_edgecolor (first_color (orig_handle .get_edgecolor ()))
605+ legend_handle .set_facecolor (first_color (orig_handle .get_facecolor ()))
606+ legend_handle .set_fill (orig_handle .get_fill ())
607+ legend_handle .set_hatch (orig_handle .get_hatch ())
608+ legend_handle .set_linewidth (get_first (orig_handle .get_linewidths ()))
609+ legend_handle .set_linestyle (get_first (orig_handle .get_linestyles ()))
610+ legend_handle .set_transform (get_first (orig_handle .get_transforms ()))
611+ legend_handle .set_figure (orig_handle .get_figure ())
612+ legend_handle .set_alpha (orig_handle .get_alpha ())
613+
614+ def create_artists (self , legend , orig_handle ,
615+ xdescent , ydescent , width , height , fontsize , trans ):
616+ p = Rectangle (xy = (- xdescent , - ydescent ),
617+ width = width , height = height )
618+ self .update_prop (p , orig_handle , legend )
619+ p .set_transform (trans )
620+ return [p ]
0 commit comments