I'm still interested in having a polygon symbol in the legend for a
scatter plot. I've made some changes to the suggestion of Manuel Metz to
make the legend symbol look better (the code-fragment from legend.py is
below). But when resizing the window, the symbol gets stretched and
placed in a bad location; it appears that the symbol is stretched and
scaled in the same manner as the legend box as a whole, while I think it
would look better if the symbol maintained the same size and aspect
ratio, but merely moved to the appropriate location within the resized
I would like to add this functionality, but I need some help to
understand the required transformations or scaling to make it look good.
Perhaps someone with a better understanding could provide some help?
elif isinstance(handle, RegularPolyCollection):
if self.numpoints == 1:
xdata = np.array([left])
for path in handle.get_paths():
xy = path.vertices
p = Polygon(xy)
x = min(xdata)
y = y-0.5*HEIGHT
# 0.35 * HEIGHT makes the legend symbol an appropriate size.
# patch_aspect scales the legend symbol to the appropriate aspect ratio.
patch_aspect = (max(xy[:,0]) - min(xy[:,0])) /
(max(xy[:,1]) - min(xy[:,1]))
bbox = Bbox.from_bounds(x, y, 0.35 * HEIGHT, 0.35 *
HEIGHT * patch_aspect)
if handle._edgecolors != 'None':
# HERE IS THE ADDITIONAL TRANSFORM FOR THE POLY
p.set_transform( BboxTransformTo(bbox) +