I'm using matplotlib 0.98 together with wxpython 126.96.36.199. It would be nice
to be able to click on the legend and move it with the mouse. Is that
possible? Is there a simple way to do this? Has anyone tried this or can
someone point in the direction?
From: Anthony Floyd <anthonyfloyd@gm...> - 2008-08-06 19:29:03
Oops, forgot to cc the list...
---------- Forwarded message ----------
From: Anthony Floyd <anthonyfloyd@...>
Date: Wed, Aug 6, 2008 at 12:28 PM
Subject: Re: [Matplotlib-users] Moving legend with mouse?
To: Søren Nielsen <soren.skou.nielsen@...>
On Fri, Aug 1, 2008 at 6:10 AM, Søren Nielsen
> I'm using matplotlib 0.98 together with wxpython 188.8.131.52. It would be nice
> to be able to click on the legend and move it with the mouse. Is that
> possible? Is there a simple way to do this? Has anyone tried this or can
> someone point in the direction?
Sorry for the delay. This is pretty easy to do if you're using the API.
Our code is pretty ... um, integrated, so I can't provide you with a
detailed step-by-step, but here's the general idea:
- On a FigureCanvas, use mpl_connect to hook into the
'motion_notify_event'. So, we have
- onMouseMove checks to see if we've previously picked the legend and
adds mplEvent.x and mplEvent.y to the original pick location and calls
our self._moveLegend function
- The _moveLegend routine is:
def _moveLegend(self, x, y, autoDraw=True):
height = float(self.figure.bbox.height())
width = float(self.figure.bbox.width())
dx = x/width
dy = y/height
self._legendLocation = (dx, dy)
Now, you won't need most of this, but the important things here are
the dx,dy calculations and the _legend._loc=(dx,dy) assignment.
It's not a very complete set of instructions, but it might get you
pointed in the right direction. Legend dragging in this manner works
quite smoothly for us.
Get latest updates about Open Source Projects, Conferences and News.