Hi, here a message I sent a while ago, but I hanen't seen it on the
ML, so here it is again, in case.
Thanks,
David Douard
pickage_legend.patch (1.19 KB)
···
---------------
Here is a simple patch that allow to make legend and its compnents
(texts, patches and lines) pickable for real.
The goal was to make this work (may be added to examples in mpl):
from pylab import *
N=100
props = dict( alpha=0.5, faceted=False )
fig=figure()
handles = []
colours = ['red', 'green', 'blue', 'magenta', 'cyan', 'yellow']
for colour in colours:
x, y = rand(2,N)
s = 400.0 * rand(N)
handles.append(scatter(x, y, c=colour, s=s, picker=True, **props))
l = legend(handles, colours, )
grid(True)
for lb in l.get_texts():
lb.set_picker(True)
def pick(event):
a = event.artist
if isinstance(a, matplotlib.text.Text):
name = event.artist.get_text()
h = handles[colours.index(name)]
h.set_visible(not h.get_visible())
draw()
fig.canvas.mpl_connect('pick_event', pick)
show()
PS: note that I am not on the mpl-devel mailing-list. Please Cc me
back in case of reply.
--
David Douard LOGILAB, Paris (France), +33 1 45 32 03 12
Formations Python, Zope, Debian : http://www.logilab.fr/formations
Développement logiciel sur mesure : http://www.logilab.fr/services
Informatique scientifique : http://www.logilab.fr/science