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 --------------- 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
Index: lib/matplotlib/legend.py =================================================================== --- lib/matplotlib/legend.py (révision 3714) +++ lib/matplotlib/legend.py (copie de travail) @@ -222,14 +222,18 @@ self._set_artist_props(self.legendPatch) self._drawFrame = True + def contains(self, mouseevent): + if callable(self._contains): return self._contains(self,mouseevent) + + return self.legendPatch.contains(mouseevent) + def _set_artist_props(self, a): a.set_figure(self.figure) a.set_transform(self.get_transform()) def _approx_text_height(self): return self.fontsize/72.0*self.figure.dpi.get()/self.parent.bbox.height() - - + def draw(self, renderer): if not self.get_visible(): return renderer.open_group('legend') @@ -404,6 +408,9 @@ 'return a list of text.Text instance in the legend' return silent_list('Text', self.texts) + def get_children(self): + return [self.get_frame()] + self.get_lines() + self.get_patches() + self.get_texts() + def _get_texts(self, labels, left, upper): # height in axes coords
signature.asc
Description: Digital signature
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel