Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

Re: [Matplotlib-users] Draggable matplotlib legend

 Re: [Matplotlib-users] Draggable matplotlib legend From: John Hunter - 2010-01-28 21:48:58 ```On Thu, Jan 28, 2010 at 3:02 PM, Adam Fraser wrote: > I thought I'd share a solution to the draggable legend problem since > it took me forever to assimilate all the scattered knowledge on the > mailing lists... Cool -- nice example. I added the code to legend.py. Now you can do leg = ax.legend() leg.draggable() to enable draggable mode. You can repeatedly call this func to toggle the draggable state. Thanks, JDH ```

 [Matplotlib-users] Draggable matplotlib legend From: Adam Fraser - 2010-01-28 21:03:01 ```I thought I'd share a solution to the draggable legend problem since it took me forever to assimilate all the scattered knowledge on the mailing lists... class DraggableLegend: def __init__(self, legend): self.legend = legend self.gotLegend = False legend.figure.canvas.mpl_connect('motion_notify_event', self.on_motion) legend.figure.canvas.mpl_connect('pick_event', self.on_pick) legend.figure.canvas.mpl_connect('button_release_event', self.on_release) legend.set_picker(self.my_legend_picker) 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 #...and in your code... def draw(self): ax = self.figure.add_subplot(111) scatter = ax.scatter(np.random.randn(100), np.random.randn(100)) legend = DraggableLegend(ax.legend()) ```
 Re: [Matplotlib-users] Draggable matplotlib legend From: John Hunter - 2010-01-28 21:48:58 ```On Thu, Jan 28, 2010 at 3:02 PM, Adam Fraser wrote: > I thought I'd share a solution to the draggable legend problem since > it took me forever to assimilate all the scattered knowledge on the > mailing lists... Cool -- nice example. I added the code to legend.py. Now you can do leg = ax.legend() leg.draggable() to enable draggable mode. You can repeatedly call this func to toggle the draggable state. Thanks, JDH ```
 Re: [Matplotlib-users] Draggable matplotlib legend From: Gökhan Sever - 2010-01-29 00:57:36 Attachments: Message as HTML ```On Thu, Jan 28, 2010 at 3:48 PM, John Hunter wrote: > On Thu, Jan 28, 2010 at 3:02 PM, Adam Fraser > wrote: > > I thought I'd share a solution to the draggable legend problem since > > it took me forever to assimilate all the scattered knowledge on the > > mailing lists... > > Cool -- nice example. I added the code to legend.py. Now you can do > > leg = ax.legend() > leg.draggable() > > to enable draggable mode. You can repeatedly call this func to toggle > the draggable state. > > Thanks, > JDH > Very useful addition for me. One question In [8]: ax.leg ax.legend ax.legend_ Has the second instance forgotten or left on purpose? > > > ------------------------------------------------------------------------------ > The Planet: dedicated and managed hosting, cloud storage, colocation > Stay online with enterprise data centers and the best network in the > business > Choose flexible plans and management services without long-term contracts > Personal 24x7 support from experience hosting pros just a phone call away. > http://p.sf.net/sfu/theplanet-com > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Gökhan ```
 Re: [Matplotlib-users] Draggable matplotlib legend From: Christopher Barker - 2010-01-29 04:00:21 ```> On Thu, Jan 28, 2010 at 3:48 PM, John Hunter Cool -- nice example. I added the code to legend.py. Now you can do > > leg = ax.legend() > leg.draggable() > > to enable draggable mode. You can repeatedly call this func to toggle > the draggable state. Might I suggest that that be made: leg.draggable(True) leg.draggable(False) or leg.draggable('on') leg.draggable('off') or even a property: leg.draggable = True or some such. I'd be nice not to have to keep track of the current state. -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception ```
 Re: [Matplotlib-users] Draggable matplotlib legend From: Fernando Perez - 2010-01-29 04:14:24 ```On Thu, Jan 28, 2010 at 8:01 PM, Christopher Barker wrote: > Might I suggest that that be made: > > leg.draggable(True) > leg.draggable(False) > Agreed. My favorite api for toggles is: _state = True def toggle(state=None): global _state old = _state if state is None: _state = not _state else: _state = state return old ### This lets you: - toggle without arguments - set state specifically as needed - save previous state before setting it if you need to make temporary changes. Cheers, f ```
 Re: [Matplotlib-users] Draggable matplotlib legend From: Michele Mattioni - 2010-01-29 09:46:33 Attachments: Message as HTML ```Good job! +1 On Fri, Jan 29, 2010 at 4:14 AM, Fernando Perez wrote: > On Thu, Jan 28, 2010 at 8:01 PM, Christopher Barker > wrote: > > Might I suggest that that be made: > > > > leg.draggable(True) > > leg.draggable(False) > > > > Agreed. My favorite api for toggles is: > > _state = True > > def toggle(state=None): > global _state > old = _state > if state is None: > _state = not _state > else: > _state = state > return old > > ### > > This lets you: > > - toggle without arguments > - set state specifically as needed > - save previous state before setting it if you need to make temporary > changes. > > Cheers, > > f > > > ------------------------------------------------------------------------------ > The Planet: dedicated and managed hosting, cloud storage, colocation > Stay online with enterprise data centers and the best network in the > business > Choose flexible plans and management services without long-term contracts > Personal 24x7 support from experience hosting pros just a phone call away. > http://p.sf.net/sfu/theplanet-com > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ```
 Re: [Matplotlib-users] Draggable matplotlib legend From: John Hunter - 2010-01-29 15:28:34 ```On Thu, Jan 28, 2010 at 10:14 PM, Fernando Perez wrote: > On Thu, Jan 28, 2010 at 8:01 PM, Christopher Barker > wrote: >> Might I suggest that that be made: >> >> leg.draggable(True) >> leg.draggable(False) >> > > Agreed.  My favorite api for toggles is: > > _state = True OK, this is committed. Thanks for the suggestion. JDH ```
 Re: [Matplotlib-users] Draggable matplotlib legend From: Jae-Joon Lee - 2010-01-29 17:41:19 ```I did some refactoring and now the annotation is also draggable.. I also added an example, examples/animation/draggable_legend.py Regards, -JJ On Fri, Jan 29, 2010 at 10:28 AM, John Hunter wrote: > On Thu, Jan 28, 2010 at 10:14 PM, Fernando Perez wrote: >> On Thu, Jan 28, 2010 at 8:01 PM, Christopher Barker >> wrote: >>> Might I suggest that that be made: >>> >>> leg.draggable(True) >>> leg.draggable(False) >>> >> >> Agreed.  My favorite api for toggles is: >> >> _state = True > > OK, this is committed.  Thanks for the suggestion. > > JDH > > ------------------------------------------------------------------------------ > The Planet: dedicated and managed hosting, cloud storage, colocation > Stay online with enterprise data centers and the best network in the business > Choose flexible plans and management services without long-term contracts > Personal 24x7 support from experience hosting pros just a phone call away. > http://p.sf.net/sfu/theplanet-com > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ```
 Re: [Matplotlib-users] Draggable matplotlib legend From: Jae-Joon Lee - 2010-01-29 18:04:14 ```added blitting support. -JJ On Fri, Jan 29, 2010 at 12:40 PM, Jae-Joon Lee wrote: > I did some refactoring and now the annotation is also draggable.. > I also added an example, > > examples/animation/draggable_legend.py > > Regards, > > -JJ > > > > On Fri, Jan 29, 2010 at 10:28 AM, John Hunter wrote: >> On Thu, Jan 28, 2010 at 10:14 PM, Fernando Perez wrote: >>> On Thu, Jan 28, 2010 at 8:01 PM, Christopher Barker >>> wrote: >>>> Might I suggest that that be made: >>>> >>>> leg.draggable(True) >>>> leg.draggable(False) >>>> >>> >>> Agreed.  My favorite api for toggles is: >>> >>> _state = True >> >> OK, this is committed.  Thanks for the suggestion. >> >> JDH >> >> ------------------------------------------------------------------------------ >> The Planet: dedicated and managed hosting, cloud storage, colocation >> Stay online with enterprise data centers and the best network in the business >> Choose flexible plans and management services without long-term contracts >> Personal 24x7 support from experience hosting pros just a phone call away. >> http://p.sf.net/sfu/theplanet-com >> _______________________________________________ >> Matplotlib-users mailing list >> Matplotlib-users@... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> > ```
 Re: [Matplotlib-users] Draggable matplotlib legend From: Gökhan Sever - 2010-01-29 18:42:49 Attachments: Message as HTML ```One minor issue with the example is once you drag one of the items (legend or text or image) out of the plotting area there is no way to move them back unless you restart the example. Do you get the same defect? On Fri, Jan 29, 2010 at 11:40 AM, Jae-Joon Lee wrote: > I did some refactoring and now the annotation is also draggable.. > I also added an example, > > examples/animation/draggable_legend.py > > Regards, > > -JJ > > > > On Fri, Jan 29, 2010 at 10:28 AM, John Hunter wrote: > > On Thu, Jan 28, 2010 at 10:14 PM, Fernando Perez > wrote: > >> On Thu, Jan 28, 2010 at 8:01 PM, Christopher Barker > >> wrote: > >>> Might I suggest that that be made: > >>> > >>> leg.draggable(True) > >>> leg.draggable(False) > >>> > >> > >> Agreed. My favorite api for toggles is: > >> > >> _state = True > > > > OK, this is committed. Thanks for the suggestion. > > > > JDH > > > > > ------------------------------------------------------------------------------ > > The Planet: dedicated and managed hosting, cloud storage, colocation > > Stay online with enterprise data centers and the best network in the > business > > Choose flexible plans and management services without long-term contracts > > Personal 24x7 support from experience hosting pros just a phone call > away. > > http://p.sf.net/sfu/theplanet-com > > _______________________________________________ > > Matplotlib-users mailing list > > Matplotlib-users@... > > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > > > > ------------------------------------------------------------------------------ > The Planet: dedicated and managed hosting, cloud storage, colocation > Stay online with enterprise data centers and the best network in the > business > Choose flexible plans and management services without long-term contracts > Personal 24x7 support from experience hosting pros just a phone call away. > http://p.sf.net/sfu/theplanet-com > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Gökhan ```