Picking on a scatter plot. Copy of positions needed?

Hello,

Looking at the picking demo:

http://matplotlib.org/examples/event_handling/pick_event_demo.html

I see that one can recover the coordinates from the picked artist in the case of images, and lines. However, in case 3 of the example (scatter plot) the x and y data have to be supplied in order to retrieve the coordinates. Is there a way to recover them from the artist? I got the (wrong?) feeling that the data must be hidden somewhere ... If that is not possible I'll have to keep a copy of the data used to generate the artist, but I would not like to do so.

Any hint?

Thanks,

Armando

It is possible. Those examples were merely showing different ways to do similar things (and there are more ways to do it, btw). The techniques can be used for different artist types. I guess the important question is, do you need the exact coordinates of the artist, or just the coordinates where the mouse clicked? If it is just the location of the mouse click, then the “xdata” and “ydata” attributes should be all you need.

For picking events, the event object will have an “artist” attribute that will point to the artist that was “picked”. For collection type artists, there should be an “ind” attribute to the event object that provides the index into the array held by the collection artist. You can then index the data contained by the collection object already. Different collection objects, unfortunately, have slightly different getters. So, while some might have get_xdata() and get_ydata(), others might have get_points() or something like that. I never get them straight in my head.

Cheers!
Ben Root

<shameless_plug>There will be some useful examples of this and a deeper explanation in my upcoming book on interactive matplotlib. Stay tuned to this mailing list for announcements</shameless_plug>

···

On Fri, Nov 14, 2014 at 9:03 AM, V. Armando Sole <sole@…291…> wrote:

Hello,

Looking at the picking demo:

http://matplotlib.org/examples/event_handling/pick_event_demo.html

I see that one can recover the coordinates from the picked artist in the

case of images, and lines. However, in case 3 of the example (scatter

plot) the x and y data have to be supplied in order to retrieve the

coordinates. Is there a way to recover them from the artist? I got the

(wrong?) feeling that the data must be hidden somewhere … If that is

not possible I’ll have to keep a copy of the data used to generate the

artist, but I would not like to do so.

Any hint?

Thanks,

Armando


Comprehensive Server Monitoring with Site24x7.

Monitor 10 servers for $9/Month.

Get alerted through email, SMS, voice calls or mobile push notifications.

Take corrective actions from your mobile device.

http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

yes, I know the exact coordinates of the marker. For lines is not a problem (using ind) but for a collection I have not found a built-in way. I have made a print(dir(artist)) and the only thing I found interesting was get_array(), but it gave me back None ...

Armando

···

On 14/11/2014 15:49, Benjamin Root wrote:

It is possible. Those examples were merely showing different ways to do similar things (and there are more ways to do it, btw). The techniques can be used for different artist types. I guess the important question is, do you need the *exact* coordinates of the artist, or just the coordinates where the mouse clicked? If it is just the location of the mouse click, then the "xdata" and "ydata" attributes should be all you need.

For picking events, the event object will have an "artist" attribute that will point to the artist that was "picked". For collection type artists, there should be an "ind" attribute to the event object that provides the index into the array held by the collection artist. You can then index the data contained by the collection object already. Different collection objects, unfortunately, have slightly different getters. So, while some might have get_xdata() and get_ydata(), others might have get_points() or something like that. I never get them straight in my head.

Just in case my previous mail was confusing. I need the "exact" coordinates of the artist.

Armando

···

On 14/11/2014 15:49, Benjamin Root wrote:

It is possible. Those examples were merely showing different ways to do similar things (and there are more ways to do it, btw). The techniques can be used for different artist types. I guess the important question is, do you need the *exact* coordinates of the artist,

Thanks a lot!

Armando

···

On 14/11/2014 16:02, Thomas Caswell wrote:

The positions are stored in offsets, the array property is the color mapping.