On Thu, Dec 9, 2010 at 8:45 PM, Jae-Joon Lee <lee.j.j...@gmail.com> wrote:
> As far as I understand, all the events in matplotlib are associated > with a single Axes instance (or None). For overlapping multiple axes, > the axes with highest zorder is picked up. And a "pick > event only works for artists in the associated axes. > When I was using matplotlib 0.98.5.2, I had the same code as I have now, with two different axes, and pick events were picked up on lines belonging to either of the axes. Unless I'm misunderstanding, something has changed and this used to be possible. Is that correct? For the example above, a workaround is to move the line to the axes of > higher zorder. > > line.remove() > ax2.add_line(line) > Thanks. That works for that example, but in my actual program I want to highlight the picked points with a star. if I reparent the one line to the other axis, the stars will be plotted on the wrong axis, way off the intended marker. This can be seen in the modification of the above code, posted below (click on the middle red marker, then the middle blue one). Is there a further workaround? (Code at bottom). I also use the identity of the picked line in my code, since I provide additional information about that data series to the user based on which line (and point) they picked. So if reparenting the line loses that information, that's going to be a problem. thanks, -Che --- import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) ax2 = ax.twinx() line, = ax.plot([1,2,5], 'r-o', markersize=15, picker=5) line2, = ax2.plot([4,5,12], 'b-o', markersize=15, picker=5) line.remove() ax2.add_line(line) def onpick(event): thisline = event.artist print 'picked line: ', event.artist ind = event.ind xdata = thisline.get_xdata() ydata = thisline.get_ydata() star, = ax.plot([xdata[ind]], [ydata[ind]], '*', ms=40, mfc='y', mec='b') fig.canvas.draw() fig.canvas.mpl_connect('pick_event', onpick) plt.show()
------------------------------------------------------------------------------
_______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users