On Wed, Jun 10, 2009 at 6:55 AM, Ole Streicher<ole-usenet-s...@gmx.net> wrote: > Hi again, > > when right-clicking on one or more lines in a plot, I want to present > the user a context menu where he can select to remove these lines. > > Preferrably I want to do this not with a 'pick_event' connection but > with the (Qt) backend methods since the context menu should contain more > options (which shall be shown also when right-clicking on the diagram > background). > > Unfortunately, I have no idea, how to do this. At first, I found only > the pick_event() which responds to a left mouse click. Is there a way to > get the Line2D instances that would be picked by specifying the mouse > position?
The pick_event is fired off with any mouse press. See the following example: you can select the line with the left or right mouse button:: import numpy as np import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) x = np.arange(10) line1, = ax.plot(x, x, picker=5, label='x') line2, = ax.plot(x, x*2, picker=5, label='x^2') def on_pick(pickevent): thisline = pickevent.artist print 'you picked line=%s with button=%s'%( thisline.get_label(), pickevent.mouseevent.button) fig.canvas.mpl_connect('pick_event', on_pick) plt.show() If for some reason the built in pick_event is unsuitable, you can create your own matplotlib.backend_bases.MouseEvent and call line.contains(event) for each line you want to hit test. http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.lines.Line2D.contains http://matplotlib.sourceforge.net/api/backend_bases_api.html#matplotlib.backend_bases.MouseEvent JDH ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users