Interative legend manipulation?

Sometimes the legend simply gets in the way. You can't always guess
the correct placement (think generic tool which processes lots of
different input data sets), or zooming/panning makes it obscure a
chunk of the plot you want to look at. Is it possible to move it
interactively? I'm using mpl 1.3.1.

Thx,

Skip

I believe (as of v1.3.1) that after you create the legend you call leg.draggable(True)
http://matplotlib.org/api/legend_api.html#matplotlib.legend.Legend.draggable

···

On Tue, Jan 7, 2014 at 6:37 AM, Skip Montanaro <skip@…789…> wrote:

Sometimes the legend simply gets in the way. You can’t always guess

the correct placement (think generic tool which processes lots of

different input data sets), or zooming/panning makes it obscure a

chunk of the plot you want to look at. Is it possible to move it

interactively? I’m using mpl 1.3.1.

Thx,

Skip


Rapidly troubleshoot problems before they affect your business. Most IT

organizations don’t have a clear picture of how application performance

affects their revenue. With AppDynamics, you get 100% visibility into your

Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!

http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

I believe (as of v1.3.1) that after you create the legend you call
leg.draggable(True)
http://matplotlib.org/api/legend_api.html#matplotlib.legend.Legend.draggable

Outstanding! (Google was not my friend here. I wasn't searching for
"draggable.")

Skip

I had never heard of that nice possibility!

Would it make sense to add a few lines to the Legend Guide/Legend location ?
http://matplotlib.org/users/legend_guide.html#legend-location

and possibly to the legend demo ?
http://matplotlib.org/examples/api/legend_demo.html

(and remove
http://matplotlib.org/examples/old_animation/draggable_legend.html ?)

best,
Pierre

···

Le 07/01/2014 17:51, Paul Hobson a écrit :

I believe (as of v1.3.1) that after you create the legend you call
leg.draggable(True)

I believe (as of v1.3.1) that after you create the legend you call
leg.draggable(True)
http://matplotlib.org/api/legend_api.html#matplotlib.legend.Legend.draggable

Outstanding! (Google was not my friend here. I wasn’t searching for
“draggable.”)

It works if I only plot using the left Y axis. If I add plots to the right Y axis it won’t drag. Basically, the code looks like this:

left_plot = figure.add_subplot(111)
… do left_plot stuff …

if I have right axis data to plot:
right_plot = left_plot.twinx()
… do right_plot stuff …

if a legend is requested:
labels = [line.get_label() for line in lines]
left_plot.legend(lines, labels).draggable(True)

figure.tight_layout()
pylab.show()

The legend is displayed correctly. It has all the desired elements, but the legend isn’t mouse sensitive. This leads me to believe that the plotting somehow makes mouse events get handled by the right Y axis subplot. If I move the cursor around the plot, the Y coordinates displayed at the bottom of the window are those of the left Y axis, however.

On that assumption, I tried changing the legend to be associated with the right Y axis:

if a legend is requested:
labels = [line.get_label() for line in lines]
if I have right axis data to plot:

    right_plot.legend(lines, labels).draggable(True)
else:
    left_plot.legend(lines, labels).draggable(True)

Again, the legend displays properly, but can’t be dragged.

Any ideas?

Thx,

Skip

On that assumption, I tried changing the legend to be associated with the
right Y axis:

if a legend is requested:
    labels = [line.get_label() for line in lines]
    if I have right axis data to plot:
        right_plot.legend(lines, labels).draggable(True)
    else:
        left_plot.legend(lines, labels).draggable(True)

Again, the legend displays properly, but can't be dragged.

Belay that. The above change does work around the problem. Still, would be
nice if this worked no matter which Y axes were used.

Skip
​​