diff --git a/lib/matplotlib/legend_handler.py b/lib/matplotlib/legend_handler.py index 263945b050d0..0173c23960cc 100644 --- a/lib/matplotlib/legend_handler.py +++ b/lib/matplotlib/legend_handler.py @@ -810,3 +810,42 @@ def create_artists(self, legend, orig_handle, self.update_prop(p, orig_handle, legend) p.set_transform(trans) return [p] + +from matplotlib.legend_handler import HandlerPatchCollection + +_default_handler_map[PatchCollection] = HandlerPatchCollection() + + +from matplotlib.patches import Patch +from matplotlib.collections import PatchCollection + +class HandlerPatchCollection(HandlerPatch): + """ + Handler for PatchCollection, e.g. from matplotlib.collections. + Uses the properties of the first patch in the collection. + """ + + def create_artists(self, legend, orig_handle, + xdescent, ydescent, width, height, fontsize, trans): + p = Patch() + + try: + fc = orig_handle.get_facecolor()[0] + ec = orig_handle.get_edgecolor()[0] + lw = orig_handle.get_linewidths()[0] + ls = orig_handle.get_linestyle()[0] + except IndexError: + fc, ec, lw, ls = 'gray', 'black', 1.0, 'solid' + + p.set_facecolor(fc) + p.set_edgecolor(ec) + p.set_linewidth(lw) + p.set_linestyle(ls) + + self.update_prop(p, orig_handle, legend) + p.set_transform(trans) + p.set_xy([[-xdescent, -ydescent], + [-xdescent + width, -ydescent], + [-xdescent + width, -ydescent + height], + [-xdescent, -ydescent + height]]) + return [p] \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy