>
> 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?

Yes, I believe this used to be possible. While I'm not sure why it
changed, I'm also not sure if we need to revert this change as I
personally prefer the current simple behavior (although there could be
a room for improvement). And I want to hear what others think. You may
file a new feature request (or a bug if you want) issue regarding
this.

>
>> 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).
>

It will work if you explicitly set its transform.

    star, = ax.plot([xdata[ind]], [ydata[ind]], '*',
                    ms=40, mfc='y', mec='b',
transform=thisline.get_transform())


> 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.
>

I believe that reparenting only changes the "axes" attribute of the
line, so it might not be a problem.

Given the current implementation of the pick event handler, I think it
might be better for you to implement a custom handler although this
may takes you more time.

However, I must admit that I rarely use events with matplotlib. I'm
only addressing this since there were no response from other
developers. And they may have different opinions than me.

Regards,

-JJ

> 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

Reply via email to