3131from font_manager import FontProperties
3232from lines import Line2D
3333from mlab import linspace , segments_intersect
34- from patches import Patch , Rectangle , Shadow , bbox_artist , draw_bbox
35- from collections import LineCollection
34+ from patches import Patch , Rectangle , RegularPolygon , Shadow , bbox_artist , draw_bbox
35+ from collections import LineCollection , RegularPolyCollection , PatchCollection
3636from text import Text
3737from transforms import Bbox , Point , Value , get_bbox_transform , bbox_all ,\
3838 unit_bbox , inverse_transform_bbox , lbwh_to_bbox
@@ -282,6 +282,18 @@ def _get_handles(self, handles, texts):
282282 legline .set_dashes (dashes )
283283 ret .append (legline )
284284
285+ elif isinstance (handle , RegularPolyCollection ):
286+
287+ p = Rectangle (xy = (min (self ._xdata ), y - 3 / 4 * HEIGHT ),
288+ width = self .handlelen , height = HEIGHT / 2 ,
289+ )
290+ p .set_facecolor (handle ._facecolors [0 ])
291+ if handle ._edgecolors != 'None' :
292+ p .set_edgecolor (handle ._edgecolors [0 ])
293+ self ._set_artist_props (p )
294+ p .set_clip_box (None )
295+ ret .append (p )
296+
285297 else :
286298 ret .append (None )
287299
@@ -307,6 +319,7 @@ def get_handles(ax):
307319 handles = ax .lines
308320 handles .extend (ax .patches )
309321 handles .extend ([c for c in ax .collections if isinstance (c , LineCollection )])
322+
310323 return handles
311324
312325 ax = self .parent
@@ -411,6 +424,8 @@ def _offset(self, ox, oy):
411424 elif isinstance (h , Rectangle ):
412425 h .xy [0 ] = h .xy [0 ] + ox
413426 h .xy [1 ] = h .xy [1 ] + oy
427+ elif isinstance (h , RegularPolygon ):
428+ h .verts = [(x + ox , y + oy ) for x , y in h .verts ]
414429
415430 x , y = self .legendPatch .get_x (), self .legendPatch .get_y ()
416431 self .legendPatch .set_x (x + ox )
0 commit comments