pick the legend? pick a point but not a connecting line?

Hi, I have two picking questions. First, If I do this inside a pick
handler function:

def OnPick(self, event):
if isinstance(event.artist, Line2D):
thisline = event.artist
xdata = thisline.get_xdata()
ydata = thisline.get_ydata()

I can grab the data from a line. Fine.

Now I’d like to do two things:

  1. WIthin this same pick handler function, have another if conditional,
    but for the case when the user is picking the legend. In other words, I
    want to pick the legend artist, not a Line2D artist.

  2. Modify the above so the user can pick only the actual points on a line,
    but not the connecting line if I have plotted it like ‘o-’ style (connected points).

I hope this is clear. Any help is appreciated. Thanks.
Che

1) WIthin this same pick handler function, have another if conditional,
but for the case when the user is picking the legend. In other words, I
want to pick the legend artist, not a Line2D artist.

I'm afraid but it is not clear what you want here (at least to me).
Can you just pick up the legend patch?
If what you want is to check if the picked-up line2d artist is one of
the legend handles, you may
explicitly do that (see the attached example code).

2) Modify the above so the user can pick only the actual points on a line,
but not the connecting line if I have plotted it like 'o-' style (connected
points).

You know the data points of the line and the position of the mouse
event, can you just check if the event is nearby the point?
You may do that before the "pick_event" is triggered, i.e., by using
the custom picker (contains) function. See the attached example. The
"contains_points" function is derived from the contain method of the
Line2D class.

Also check the examples under the event_handling directory.

-JJ

pick_event_demo.py (1.74 KB)

···

I hope this is clear. Any help is appreciated. Thanks.
Che

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options