Skip to content

Commit f98d889

Browse files
committed
Fix markerscale and scatterpoints keyword arguments in legend. Thanks to Erik Tollerud
svn path=/trunk/matplotlib/; revision=8418
1 parent f4a598a commit f98d889

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

lib/matplotlib/legend.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def finalize_offset(self):
5353
bbox = self.legend.get_bbox_to_anchor()
5454
_bbox_transform = BboxTransformFrom(bbox)
5555
self.legend._loc = tuple(_bbox_transform.transform_point(loc_in_canvas))
56-
56+
5757

5858

5959
class Legend(Artist):
@@ -256,7 +256,7 @@ def __init__(self, parent, handles, labels,
256256
self._scatteryoffsets = np.array([3./8., 4./8., 2.5/8.])
257257
else:
258258
self._scatteryoffsets = np.asarray(scatteryoffsets)
259-
reps = int(self.numpoints / len(self._scatteryoffsets)) + 1
259+
reps = int(self.scatterpoints / len(self._scatteryoffsets)) + 1
260260
self._scatteryoffsets = np.tile(self._scatteryoffsets, reps)[:self.scatterpoints]
261261

262262
# _legend_box is an OffsetBox instance that contains all
@@ -519,6 +519,9 @@ def _init_legend_box(self, handles, labels):
519519
legline_marker.set_clip_box(None)
520520
legline_marker.set_clip_path(None)
521521
legline_marker.set_linestyle('None')
522+
if self.markerscale !=1:
523+
newsz = legline_marker.get_markersize()*self.markerscale
524+
legline_marker.set_markersize(newsz)
522525
# we don't want to add this to the return list because
523526
# the texts and handles are assumed to be in one-to-one
524527
# correpondence.
@@ -554,11 +557,8 @@ def _init_legend_box(self, handles, labels):
554557
#ydata = self._scatteryoffsets
555558
ydata = height*self._scatteryoffsets
556559

557-
size_max, size_min = max(handle.get_sizes()),\
558-
min(handle.get_sizes())
559-
# we may need to scale these sizes by "markerscale"
560-
# attribute. But other handle types does not seem
561-
# to care about this attribute and it is currently ignored.
560+
size_max, size_min = max(handle.get_sizes())*self.markerscale**2,\
561+
min(handle.get_sizes())*self.markerscale**2
562562
if self.scatterpoints < 4:
563563
sizes = [.5*(size_max+size_min), size_max,
564564
size_min]
@@ -582,11 +582,8 @@ def _init_legend_box(self, handles, labels):
582582

583583
ydata = height*self._scatteryoffsets
584584

585-
size_max, size_min = max(handle.get_sizes()),\
586-
min(handle.get_sizes())
587-
# we may need to scale these sizes by "markerscale"
588-
# attribute. But other handle types does not seem
589-
# to care about this attribute and it is currently ignored.
585+
size_max, size_min = max(handle.get_sizes())*self.markerscale**2,\
586+
min(handle.get_sizes())*self.markerscale**2
590587
if self.scatterpoints < 4:
591588
sizes = [.5*(size_max+size_min), size_max,
592589
size_min]
@@ -937,7 +934,7 @@ def draggable(self, state=None, use_blit=False):
937934
* True : turn draggable on
938935
939936
* False : turn draggable off
940-
937+
941938
If draggable is on, you can drag the legend on the canvas with
942939
the mouse. The DraggableLegend helper instance is returned if
943940
draggable is on.
@@ -947,7 +944,7 @@ def draggable(self, state=None, use_blit=False):
947944
# if state is None we'll toggle
948945
if state is None:
949946
state = not is_draggable
950-
947+
951948
if state:
952949
if self._draggable is None:
953950
self._draggable = DraggableLegend(self, use_blit)

0 commit comments

Comments
 (0)