From: butterw <bu...@gm...> - 2009-09-27 14:13:05
|
Hi, thank you for clearing that up. Some feedback: If plotting a line2D as discrete points rather than a continuous line, you must use numpoints=2 for the legend picking to actually occur on the points. The alpha blending doesn't work on the legend symbols however. Is there any other way, I can show in the legend whether the points of the series are visible or not ? I thought of changing the labels, but failed to get them to redraw. # plots: ax.plot(t, y1, 'ro', picker=5, label='lab1') ax.plot(t, y2, 'bo', picker=5, label='lab2') # legend leg = ax.legend(loc='upper left', numpoints=2, fancybox=True, shadow=True) lines, labels = ax.get_legend_handles_labels() # Enable picking on the legend lines leglines=leg.get_lines() for legline in leglines: legline.set_picker(5) Jae-Joon Lee wrote: > > On Wed, Sep 23, 2009 at 3:27 PM, butterw <bu...@gm...> wrote: >> >> Hi, >> >> pickers work great to make matplotlib plots more interactive/general user >> friendly. >> >> On the subject of the legend_picker.py example, I was wondering if it was >> possible to combine both a legend picker and a line picker in the same >> plot. >> From what I gather they will both use the same onpick event callback. >> >> So my question is : How do I discriminate between a pick on the legend >> from >> a pick on a line ? The event.artist is a line2D in both cases. > > As demonstrated in the above example, leg.get_lines() gives you the > list of lines inside the legend. The list of original lines is kept in > ax.lines. > So, you can check in which list the given artist is. > > Regards, > > -JJ > >> >> >> >> >> >> >> John Hunter-4 wrote: >>> >>> On Mon, Aug 3, 2009 at 11:38 PM, Gökhan Sever<gok...@gm...> >>> wrote: >>>> Hello, >>>> >>>> I was wondering if it is possible to hide some data on figures using a >>>> say >>>> right click option to any of the legend entry and make it temporarily >>>> hidden/visible to better analyse the rest of the data? >>>> >>>> Check this screenshot for example: >>>> >>>> http://img25.imageshack.us/img25/9427/datahiding.png >>>> >>>> The red data clutters the rest of the figure, and I would like to be >>>> able >>>> to >>>> hide it temporarily so that I can investigate the other two relations >>>> more >>>> easily. >>>> >>>> Any ideas? or alternative solutions? >>> >>> It's a nice idea, and should be doable with the pick interface we have >>> for all mpl artists. Unfortunately, there were a few problems in the >>> legend implementation which blocked the pick events from hitting the >>> proxy lines they contained. I just made a few changes to mpl svn HEAD >>> to support this, and added a new example. >>> >>> examples/event_handling/legend_picking.py >>> >>> which I'll include below. JJ could you review the changes to >>> legend.py? >>> >>> Instructions for checking out svn are at:: >>> >>> >>> http://matplotlib.sourceforge.net/faq/installing_faq.html#install-from-svn >>> >>> Here is the example: >>> >>> """ >>> Enable picking on the legend to toggle the legended line on and off >>> """ >>> import numpy as np >>> import matplotlib.pyplot as plt >>> >>> t = np.arange(0.0, 0.2, 0.1) >>> y1 = 2*np.sin(2*np.pi*t) >>> y2 = 4*np.sin(2*np.pi*2*t) >>> >>> fig = plt.figure() >>> ax = fig.add_subplot(111) >>> >>> line1, = ax.plot(t, y1, lw=2, color='red', label='1 hz') >>> line2, = ax.plot(t, y2, lw=2, color='blue', label='2 hz') >>> >>> leg = ax.legend(loc='upper left', fancybox=True, shadow=True) >>> leg.get_frame().set_alpha(0.4) >>> >>> >>> lines = [line1, line2] >>> lined = dict() >>> for legline, realine in zip(leg.get_lines(), lines): >>> legline.set_picker(5) # 5 pts tolerance >>> lined[legline] = realine >>> >>> def onpick(event): >>> legline = event.artist >>> realline = lined[legline] >>> vis = realline.get_visible() >>> realline.set_visible(not vis) >>> fig.canvas.draw() >>> >>> fig.canvas.mpl_connect('pick_event', onpick) >>> >>> plt.show() >>> >>> ------------------------------------------------------------------------------ >>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 >>> 30-Day >>> trial. Simplify your report design, integration and deployment - and >>> focus >>> on >>> what you do best, core application coding. Discover what's new with >>> Crystal Reports now. http://p.sf.net/sfu/bobj-july >>> _______________________________________________ >>> Matplotlib-users mailing list >>> Mat...@li... >>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >>> >>> >> >> -- >> View this message in context: >> http://www.nabble.com/Hiding-data-via-legend-tp24802219p25531267.html >> Sent from the matplotlib - users mailing list archive at Nabble.com. >> >> >> ------------------------------------------------------------------------------ >> Come build with us! The BlackBerry® Developer Conference in SF, CA >> is the only developer event you need to attend this year. Jumpstart your >> developing skills, take BlackBerry mobile applications to market and stay >> ahead of the curve. Join us from November 9-12, 2009. Register >> now! >> http://p.sf.net/sfu/devconf >> _______________________________________________ >> Matplotlib-users mailing list >> Mat...@li... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry® Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9-12, 2009. Register > now! > http://p.sf.net/sfu/devconf > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- View this message in context: http://www.nabble.com/Hiding-data-via-legend-tp24802219p25633860.html Sent from the matplotlib - users mailing list archive at Nabble.com. |