From: <mme...@us...> - 2008-10-20 09:09:14
|
Revision: 6281 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6281&view=rev Author: mmetz_bn Date: 2008-10-20 09:04:54 +0000 (Mon, 20 Oct 2008) Log Message: ----------- fix legend prop bug; yoffset not a prop Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/legend.py Modified: trunk/matplotlib/lib/matplotlib/legend.py =================================================================== --- trunk/matplotlib/lib/matplotlib/legend.py 2008-10-20 07:52:58 UTC (rev 6280) +++ trunk/matplotlib/lib/matplotlib/legend.py 2008-10-20 09:04:54 UTC (rev 6281) @@ -119,9 +119,9 @@ Artist.__init__(self) proplist=[numpoints, pad, borderpad, markerscale, labelsep, - handlelen, handletextsep, axespad, shadow, scatteryoffsets] + handlelen, handletextsep, axespad, shadow] propnames=['numpoints', 'pad', 'borderpad', 'markerscale', 'labelsep', - 'handlelen', 'handletextsep', 'axespad', 'shadow', 'scatteryoffsets'] + 'handlelen', 'handletextsep', 'axespad', 'shadow'] for name, value in safezip(propnames,proplist): if value is None: value=rcParams["legend."+name] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2008-12-05 00:08:45
|
Revision: 6495 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6495&view=rev Author: leejjoon Date: 2008-12-05 00:08:43 +0000 (Fri, 05 Dec 2008) Log Message: ----------- minor fix for legend.py Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/legend.py Modified: trunk/matplotlib/lib/matplotlib/legend.py =================================================================== --- trunk/matplotlib/lib/matplotlib/legend.py 2008-12-05 00:06:26 UTC (rev 6494) +++ trunk/matplotlib/lib/matplotlib/legend.py 2008-12-05 00:08:43 UTC (rev 6495) @@ -383,7 +383,7 @@ labelboxes = [] for l in labels: - textbox = TextArea(l, textprops=label_prop + textbox = TextArea(l, textprops=label_prop, multilinebaseline=True, minimumdescent=True) text_list.append(textbox._text) labelboxes.append(textbox) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2009-04-30 17:31:30
|
Revision: 7075 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7075&view=rev Author: leejjoon Date: 2009-04-30 17:31:23 +0000 (Thu, 30 Apr 2009) Log Message: ----------- add kwarg bbox_transform for legend. bbox_to_anchor now can be a BboxBase instance Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/legend.py Modified: trunk/matplotlib/lib/matplotlib/legend.py =================================================================== --- trunk/matplotlib/lib/matplotlib/legend.py 2009-04-30 17:05:27 UTC (rev 7074) +++ trunk/matplotlib/lib/matplotlib/legend.py 2009-04-30 17:31:23 UTC (rev 7075) @@ -32,7 +32,7 @@ from matplotlib.lines import Line2D from matplotlib.patches import Patch, Rectangle, Shadow, FancyBboxPatch from matplotlib.collections import LineCollection, RegularPolyCollection -from matplotlib.transforms import Bbox, TransformedBbox, BboxTransformTo +from matplotlib.transforms import Bbox, BboxBase, TransformedBbox, BboxTransformTo from matplotlib.offsetbox import HPacker, VPacker, TextArea, DrawingArea @@ -112,7 +112,8 @@ fancybox=None, # True use a fancy box, false use a rounded box, none use rc shadow = None, title = None, # set a title for the legend - bbox_to_anchor = None, # bbox thaw the legend will be anchored. + bbox_to_anchor = None, # bbox that the legend will be anchored. + bbox_transform = None, # transform for the bbox ): """ - *parent* : the artist that contains the legend @@ -138,11 +139,16 @@ borderaxespad the pad between the axes and legend border columnspacing the spacing between columns title the legend title - bbox_to_anchor the bbox that the legend will be anchored. + bbox_to_anchor the bbox that the legend will be anchored. + bbox_transform the transform for the bbox. transAxes if None. ================ ================================================================== The dimensions of pad and spacing are given as a fraction of the _fontsize. Values from rcParams will be used if None. + +bbox_to_anchor can be an instance of BboxBase(or its derivatives) or a +tuple of 2 or 4 floats. See :meth:`set_bbox_to_anchor` for more +detail. """ from matplotlib.axes import Axes # local import only to avoid circularity from matplotlib.figure import Figure # local import only to avoid circularity @@ -251,7 +257,7 @@ self._loc = loc self._mode = mode - self.set_bbox_to_anchor(bbox_to_anchor) + self.set_bbox_to_anchor(bbox_to_anchor, bbox_transform) # We use FancyBboxPatch to draw a legend frame. The location # and size of the box will be updated during the drawing time. @@ -689,14 +695,15 @@ """ set the bbox that the legend will be anchored. - *bbox* can be a Bbox instance, a list of [left, bottom, width, - height] in normalized axes coordinate, or a list of [left, - bottom] where the width and height will be assumed to be zero. + *bbox* can be a BboxBase instance, a tuple of [left, bottom, + width, height] in the given transform (normalized axes + coordinate if None), or a tuple of [left, bottom] where the + width and height will be assumed to be zero. """ if bbox is None: self._bbox_to_anchor = None return - elif isinstance(bbox, Bbox): + elif isinstance(bbox, BboxBase): self._bbox_to_anchor = bbox else: try: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <as...@us...> - 2009-05-27 16:24:55
|
Revision: 7143 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7143&view=rev Author: astraw Date: 2009-05-27 16:24:53 +0000 (Wed, 27 May 2009) Log Message: ----------- fix typo Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/legend.py Modified: trunk/matplotlib/lib/matplotlib/legend.py =================================================================== --- trunk/matplotlib/lib/matplotlib/legend.py 2009-05-25 18:23:25 UTC (rev 7142) +++ trunk/matplotlib/lib/matplotlib/legend.py 2009-05-27 16:24:53 UTC (rev 7143) @@ -305,7 +305,7 @@ def _findoffset_best(self, width, height, xdescent, ydescent, renderer): - "Heper function to locate the legend at its best position" + "Helper function to locate the legend at its best position" ox, oy = self._find_best_position(width, height, renderer) return ox+xdescent, oy+ydescent This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2009-05-29 15:59:48
|
Revision: 7163 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7163&view=rev Author: jdh2358 Date: 2009-05-29 15:59:47 +0000 (Fri, 29 May 2009) Log Message: ----------- fixed a buglet in legend when len(handles)==1 and ncol=2 Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/legend.py Modified: trunk/matplotlib/lib/matplotlib/legend.py =================================================================== --- trunk/matplotlib/lib/matplotlib/legend.py 2009-05-29 03:52:32 UTC (rev 7162) +++ trunk/matplotlib/lib/matplotlib/legend.py 2009-05-29 15:59:47 UTC (rev 7163) @@ -110,7 +110,7 @@ mode=None, # mode for horizontal distribution of columns. None, "expand" fancybox=None, # True use a fancy box, false use a rounded box, none use rc - shadow = None, + shadow = None, title = None, # set a title for the legend bbox_to_anchor = None, # bbox that the legend will be anchored. bbox_transform = None, # transform for the bbox @@ -139,7 +139,7 @@ borderaxespad the pad between the axes and legend border columnspacing the spacing between columns title the legend title - bbox_to_anchor the bbox that the legend will be anchored. + bbox_to_anchor the bbox that the legend will be anchored. bbox_transform the transform for the bbox. transAxes if None. ================ ================================================================== @@ -204,6 +204,9 @@ del localdict + handles = list(handles) + if len(handles)<2: + ncol = 1 self._ncol = ncol if self.numpoints <= 0: @@ -258,7 +261,7 @@ self._loc = loc self._mode = mode self.set_bbox_to_anchor(bbox_to_anchor, bbox_transform) - + # We use FancyBboxPatch to draw a legend frame. The location # and size of the box will be updated during the drawing time. self.legendPatch = FancyBboxPatch( @@ -578,13 +581,13 @@ sep = self.columnspacing*fontsize - self._legend_handle_box = HPacker(pad=0, + self._legend_handle_box = HPacker(pad=0, sep=sep, align="baseline", mode=mode, children=columnbox) self._legend_title_box = TextArea("") - + self._legend_box = VPacker(pad=self.borderpad*fontsize, sep=self.labelspacing*fontsize, align="center", @@ -722,9 +725,9 @@ self._bbox_to_anchor = TransformedBbox(self._bbox_to_anchor, transform) - - + + def _get_anchored_bbox(self, loc, bbox, parentbbox, renderer): """ Place the *bbox* inside the *parentbbox* according to a given This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2010-01-28 21:46:19
|
Revision: 8100 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8100&view=rev Author: jdh2358 Date: 2010-01-28 21:46:12 +0000 (Thu, 28 Jan 2010) Log Message: ----------- added drabbable state to legend -- thanks Adam Fraser Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/legend.py Modified: trunk/matplotlib/lib/matplotlib/legend.py =================================================================== --- trunk/matplotlib/lib/matplotlib/legend.py 2010-01-28 20:37:46 UTC (rev 8099) +++ trunk/matplotlib/lib/matplotlib/legend.py 2010-01-28 21:46:12 UTC (rev 8100) @@ -38,6 +38,51 @@ from matplotlib.offsetbox import HPacker, VPacker, TextArea, DrawingArea +class DraggableLegend: + """helper code for a draggable legend -- see Legend.draggable""" + + def __init__(self, legend): + self.legend = legend + self.gotLegend = False + + c1 = legend.figure.canvas.mpl_connect('motion_notify_event', self.on_motion) + c2 = legend.figure.canvas.mpl_connect('pick_event', self.on_pick) + c3 = legend.figure.canvas.mpl_connect('button_release_event', self.on_release) + legend.set_picker(self.my_legend_picker) + self.cids = [c1, c2, c3] + + def on_motion(self, evt): + if self.gotLegend: + dx = evt.x - self.mouse_x + dy = evt.y - self.mouse_y + loc_in_canvas = self.legend_x + dx, self.legend_y + dy + loc_in_norm_axes = self.legend.parent.transAxes.inverted().transform_point(loc_in_canvas) + self.legend._loc = tuple(loc_in_norm_axes) + self.legend.figure.canvas.draw() + + def my_legend_picker(self, legend, evt): + return self.legend.legendPatch.contains(evt) + + def on_pick(self, evt): + legend = self.legend + if evt.artist == legend: + bbox = self.legend.get_window_extent() + self.mouse_x = evt.mouseevent.x + self.mouse_y = evt.mouseevent.y + self.legend_x = bbox.xmin + self.legend_y = bbox.ymin + self.gotLegend = 1 + + def on_release(self, event): + if self.gotLegend: + self.gotLegend = False + + def disconnect(self): + 'disconnect the callbacks' + for cid in self.cids: + self.legend.figure.canvas.mpl_disconnect(cid) + + class Legend(Artist): """ Place a legend on the axes at location loc. Labels are a @@ -182,7 +227,7 @@ self.texts = [] self.legendHandles = [] self._legend_title_box = None - + localdict = locals() for name in propnames: @@ -284,7 +329,7 @@ # We use FancyBboxPatch to draw a legend frame. The location # and size of the box will be updated during the drawing time. - + self.legendPatch = FancyBboxPatch( xy=(0.0, 0.0), width=1., height=1., facecolor=rcParams["axes.facecolor"], @@ -316,6 +361,7 @@ self._last_fontsize_points = self._fontsize + self._draggable = None def _set_artist_props(self, a): """ @@ -584,7 +630,7 @@ textbox = TextArea(lab, textprops=label_prop, multilinebaseline=True, minimumdescent=True) text_list.append(textbox._text) - + labelboxes.append(textbox) handlebox = DrawingArea(width=self.handlelength*fontsize, @@ -597,7 +643,7 @@ handleboxes.append(handlebox) - if len(handleboxes) > 0: + if len(handleboxes) > 0: # We calculate number of lows in each column. The first # (num_largecol) columns will have (nrows+1) rows, and remaing @@ -613,7 +659,7 @@ [nrows] * num_smallcol) else: largecol, smallcol = [], [] - + handle_label = safezip(handleboxes, labelboxes) columnbox = [] for i0, di in largecol+smallcol: @@ -889,3 +935,16 @@ return ox, oy + def draggable(self): + """ + toggle the draggable state; if on, you can drag the legend on + the canvas. The DraggableLegend helper class is returned + """ + if self._draggable is not None: + self._draggable.disconnect() + self._draggable = None + else: + + self._draggable = DraggableLegend(self) + + return self._draggable This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2010-06-12 16:07:50
|
Revision: 8418 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8418&view=rev Author: leejjoon Date: 2010-06-12 16:07:42 +0000 (Sat, 12 Jun 2010) Log Message: ----------- Fix markerscale and scatterpoints keyword arguments in legend. Thanks to Erik Tollerud Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/legend.py Modified: trunk/matplotlib/lib/matplotlib/legend.py =================================================================== --- trunk/matplotlib/lib/matplotlib/legend.py 2010-06-12 07:48:54 UTC (rev 8417) +++ trunk/matplotlib/lib/matplotlib/legend.py 2010-06-12 16:07:42 UTC (rev 8418) @@ -53,9 +53,9 @@ bbox = self.legend.get_bbox_to_anchor() _bbox_transform = BboxTransformFrom(bbox) self.legend._loc = tuple(_bbox_transform.transform_point(loc_in_canvas)) - + class Legend(Artist): """ Place a legend on the axes at location loc. Labels are a @@ -256,7 +256,7 @@ self._scatteryoffsets = np.array([3./8., 4./8., 2.5/8.]) else: self._scatteryoffsets = np.asarray(scatteryoffsets) - reps = int(self.numpoints / len(self._scatteryoffsets)) + 1 + reps = int(self.scatterpoints / len(self._scatteryoffsets)) + 1 self._scatteryoffsets = np.tile(self._scatteryoffsets, reps)[:self.scatterpoints] # _legend_box is an OffsetBox instance that contains all @@ -519,6 +519,9 @@ legline_marker.set_clip_box(None) legline_marker.set_clip_path(None) legline_marker.set_linestyle('None') + if self.markerscale !=1: + newsz = legline_marker.get_markersize()*self.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. @@ -554,11 +557,8 @@ #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. + size_max, size_min = max(handle.get_sizes())*self.markerscale**2,\ + min(handle.get_sizes())*self.markerscale**2 if self.scatterpoints < 4: sizes = [.5*(size_max+size_min), size_max, size_min] @@ -582,11 +582,8 @@ 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. + size_max, size_min = max(handle.get_sizes())*self.markerscale**2,\ + min(handle.get_sizes())*self.markerscale**2 if self.scatterpoints < 4: sizes = [.5*(size_max+size_min), size_max, size_min] @@ -937,7 +934,7 @@ * True : turn draggable on * False : turn draggable off - + If draggable is on, you can drag the legend on the canvas with the mouse. The DraggableLegend helper instance is returned if draggable is on. @@ -947,7 +944,7 @@ # if state is None we'll toggle if state is None: state = not is_draggable - + if state: if self._draggable is None: self._draggable = DraggableLegend(self, use_blit) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2010-11-09 07:47:00
|
Revision: 8784 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8784&view=rev Author: leejjoon Date: 2010-11-09 07:46:54 +0000 (Tue, 09 Nov 2010) Log Message: ----------- DraggableLegend can optionally update *bbox_to_anchor* instead of *loc* Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/legend.py Modified: trunk/matplotlib/lib/matplotlib/legend.py =================================================================== --- trunk/matplotlib/lib/matplotlib/legend.py 2010-11-09 06:57:17 UTC (rev 8783) +++ trunk/matplotlib/lib/matplotlib/legend.py 2010-11-09 07:46:54 UTC (rev 8784) @@ -39,8 +39,19 @@ class DraggableLegend(DraggableOffsetBox): - def __init__(self, legend, use_blit=False): + def __init__(self, legend, use_blit=False, update="loc"): + """ + update : If "loc", update *loc* parameter of + legend upon finalizing. If "bbox", update + *bbox_to_anchor* parameter. + """ self.legend=legend + + if update in ["loc", "bbox"]: + self._update = update + else: + raise ValueError("update parameter '%s' is not supported." % update) + DraggableOffsetBox.__init__(self, legend, legend._legend_box, use_blit=use_blit) @@ -50,6 +61,14 @@ def finalize_offset(self): loc_in_canvas = self.get_loc_in_canvas() + if self._update == "loc": + self._update_loc(loc_in_canvas) + elif self._update == "bbox": + self._update_bbox_to_anchor(loc_in_canvas) + else: + raise RuntimeError("update parameter '%s' is not supported." % self.update) + + def _update_loc(self, loc_in_canvas): bbox = self.legend.get_bbox_to_anchor() # if bbox has zero width or height, the transformation is @@ -62,6 +81,14 @@ self.legend._loc = tuple(_bbox_transform.transform_point(loc_in_canvas)) + def _update_bbox_to_anchor(self, loc_in_canvas): + + tr = self.legend.axes.transAxes + loc_in_bbox = tr.transform_point(loc_in_canvas) + + self.legend.set_bbox_to_anchor(loc_in_bbox) + + class Legend(Artist): """ Place a legend on the axes at location loc. Labels are a @@ -931,7 +958,7 @@ return ox, oy - def draggable(self, state=None, use_blit=False): + def draggable(self, state=None, use_blit=False, update="loc"): """ Set the draggable state -- if state is @@ -944,6 +971,10 @@ If draggable is on, you can drag the legend on the canvas with the mouse. The DraggableLegend helper instance is returned if draggable is on. + + The update parameter control which parameter of the legend changes + when dragged. If update is "loc", the *loc* paramter of the legend + is changed. If "bbox", the *bbox_to_anchor* parameter is changed. """ is_draggable = self._draggable is not None @@ -953,7 +984,7 @@ if state: if self._draggable is None: - self._draggable = DraggableLegend(self, use_blit) + self._draggable = DraggableLegend(self, use_blit, update=update) else: if self._draggable is not None: self._draggable.disconnect() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |