[Matplotlib-users] selecting points inside plot

Jean-Philippe Grivet jean-philippe.grivet at wanadoo.fr
Sat Sep 2 10:01:17 EDT 2017

Thank you for the very interesting refeerences.  However, I find that 
the various programs are rather
involved and that they do not exactly answer my needs. The simplest 
program is probably the following
(from the boook by B. Root). It seems to be a step in the right direction!

import matplotlib.pyplot as plt

def process_key(event):
     print("Key:", event.key)
def process_button(event):
     print("Button:", event.x, event.y, event.xdata, event.ydata, 

fig, ax = plt.subplots(1, 1)
fig.canvas.mpl_connect('key_press_event', process_key)
fig.canvas.mpl_connect('button_press_event', process_button)

So now, how do I retrieve the values event.xdata, event.ydata s(everal 
times) in
order to use them in the main program ? (By the way, this is pretty easy
in Matlab: the function xclick the mouse coordinates and index of the 
Thank you soluch for your help.
JP Grivet

Le 30/08/2017 04:13, Thomas Caswell a écrit :
> Jean,
> What you want to do is totally possible!
> I suggest having a look at the examples in 
> https://matplotlib.org/examples/widgets/index.html the `ginput` 
> method, https://github.com/tacaswell/interactive_mpl_tutorial and Ben 
> Root's book 
> https://www.amazon.com/Interactive-Applications-using-Matplotlib-Benjamin/dp/1783988843 
> Tom

L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.

More information about the Matplotlib-users mailing list