I noticed some odd behavior in the legend and managed to track down
the source of the problem and make a fix (a diff against the current
svn is attached). Specifically, two things were fixed:
*The "markerscale" argument for the legend seems to do nothing... The
attached diff properly applies the markerscale scaling for
polygon/circle collections and the markers for lines with markers (but
NOT patches or the width of lines elements in the legend).
*If the "scatterpoints" argument was >3, all points beyond 3
disappeared. This was because the default scatteryoffset only had 3
entries, so if you didn't specifically overwrite this, the points
beyond 3 didn't appear. I've re-worked this so that now the default
properly deals with a number of points other than 3.
Index: lib/matplotlib/legend.py
===================================================================
--- lib/matplotlib/legend.py (revision 8396)
+++ lib/matplotlib/legend.py (working copy)
@@ -253,7 +253,15 @@
# introduce y-offset for handles of the scatter plot
if scatteryoffsets is None:
- self._scatteryoffsets = np.array([3./8., 4./8., 2.5/8.])
+ if scatterpoints<2:
+ self._scatteryoffsets = np.array([.5])
+ elif scatterpoints==2:
+ self._scatteryoffsets = np.array([.5,.5])
+ elif scatterpoints==3:
+ self._scatteryoffsets = np.array([3./8., 4./8., 2.5/8.])
+ else:
+ self._scatteryoffsets = np.ones(scatterpoints)*(3./8.)
+ self._scatteryoffsets[1::2] = 4./8.
else:
self._scatteryoffsets = np.asarray(scatteryoffsets)
reps = int(self.numpoints / len(self._scatteryoffsets)) + 1
@@ -446,6 +454,7 @@
"""
fontsize = self._fontsize
+ markerscale = self.markerscale
# legend_box is a HPacker, horizontally packed with
# columns. Each column is a VPacker, vertically packed with
@@ -519,6 +528,9 @@
legline_marker.set_clip_box(None)
legline_marker.set_clip_path(None)
legline_marker.set_linestyle('None')
+ if markerscale !=1:
+ newsz = legline_marker.get_markersize()*markerscale
+ legline_marker.set_markersize(newsz)
# we don't want to add this to the return list because
# the texts and handles are assumed to be in one-to-one
# correpondence.
@@ -551,23 +563,20 @@
elif isinstance(handle, RegularPolyCollection):
- #ydata = self._scatteryoffsets
ydata = height*self._scatteryoffsets
size_max, size_min = max(handle.get_sizes()),\
min(handle.get_sizes())
- # we may need to scale these sizes by "markerscale"
- # attribute. But other handle types does not seem
- # to care about this attribute and it is currently ignored.
+
if self.scatterpoints < 4:
- sizes = [.5*(size_max+size_min), size_max,
- size_min]
+ sizes = np.array([.5*(size_max+size_min), size_max,
+ size_min])
else:
sizes = (size_max-size_min)*np.linspace(0,1,self.scatterpoints)+size_min
p = type(handle)(handle.get_numsides(),
rotation=handle.get_rotation(),
- sizes=sizes,
+ sizes=sizes*markerscale,
offsets=zip(xdata_marker,ydata),
transOffset=self.get_transform(),
)
@@ -588,12 +597,12 @@
# attribute. But other handle types does not seem
# to care about this attribute and it is currently ignored.
if self.scatterpoints < 4:
- sizes = [.5*(size_max+size_min), size_max,
- size_min]
+ sizes = np.array([.5*(size_max+size_min), size_max,
+ size_min])
else:
sizes = (size_max-size_min)*np.linspace(0,1,self.scatterpoints)+size_min
- p = type(handle)(sizes,
+ p = type(handle)(sizes*markerscale,
offsets=zip(xdata_marker,ydata),
transOffset=self.get_transform(),
)
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel