<div dir="ltr"><div>If you assign a class method as the callbacks, such as process_button(self, event), then that method could save the relevant values to itself. I show how to do this in my book (as well as the global approach, too).<br></div><div><br></div><div>Cheers!<br></div>Ben Root<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Sep 2, 2017 at 10:30 AM, Jody Klymak <span dir="ltr"><<a href="mailto:jklymak@uvic.ca" target="_blank">jklymak@uvic.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>




<div>
<div style="font-family:sans-serif"><div style="white-space:normal">
<p dir="auto">Hi Jean-Philippe</p>

<p dir="auto">There may be a fancier way, but you can just declare a global in <code>process_button</code> to pass the value to a global variable.</p>

<p dir="auto">Cheers,   Jody</p>

<pre style="border:thin solid gray;margin-left:15px;margin-right:15px;max-width:90vw;overflow-x:auto;padding:5px"><code>import matplotlib.pyplot as plt

x = []

def process_key(event):
    print("Key:", event.key)
def process_button(event):
    global x
    print("Button:", event.x, event.y, event.xdata, event.ydata, event.button)
    x += [event.xdata]

fig, ax = plt.subplots(1, 1)
fig.canvas.mpl_connect('key_<wbr>press_event', process_key)
fig.canvas.mpl_connect('<wbr>button_press_event', process_button)
plt.show()

print(x)

</code></pre><div><div class="h5">

<p dir="auto">On 2 Sep 2017, at 7:01, Jean-Philippe Grivet wrote:</p>

<p dir="auto"></p></div></div></div><div><div class="h5">
<div style="white-space:normal"><blockquote style="border-left:2px solid #5855d5;color:#5855d5;margin:0 0 5px;padding-left:5px"><p dir="auto">Hi<br>
Thank you for the very interesting refeerences.  However, I find that the various programs are rather<br>
involved and that they do not exactly answer my needs. The simplest program is probably the following<br>
(from the boook by B. Root). It seems to be a step in the right direction!<br>
<br>
import matplotlib.pyplot as plt<br>
<br>
def process_key(event):<br>
    print("Key:", event.key)<br>
def process_button(event):<br>
    print("Button:", event.x, event.y, event.xdata, event.ydata, event.button)<br>
<br>
fig, ax = plt.subplots(1, 1)<br>
fig.canvas.mpl_connect('key_<wbr>press_event', process_key)<br>
fig.canvas.mpl_connect('<wbr>button_press_event', process_button)<br>
plt.show()<br>
<br>
So now, how do I retrieve the values event.xdata, event.ydata s(everal times) in<br>
order to use them in the main program ? (By the way, this is pretty easy<br>
in Matlab: the function xclick the mouse coordinates and index of the button<br>
pressed).<br>
Thank you soluch for your help.<br>
JP Grivet<br>
<br>
<br>
Le 30/08/2017 04:13, Thomas Caswell a écrit :</p>
<blockquote style="border-left:2px solid #5855d5;color:#00afcc;margin:0 0 5px;padding-left:5px;border-left-color:#00afcc"><p dir="auto">Jean,<br>
<br>
What you want to do is totally possible!<br>
<br>
I suggest having a look at the examples in <a href="https://matplotlib.org/examples/widgets/index.html" target="_blank">https://matplotlib.org/<wbr>examples/widgets/index.html</a> the `ginput` method, <a href="https://github.com/tacaswell/interactive_mpl_tutorial" target="_blank">https://github.com/tacaswell/<wbr>interactive_mpl_tutorial</a> and Ben Root's book <a href="https://www.amazon.com/Interactive-Applications-using-Matplotlib-Benjamin/dp/1783988843" target="_blank">https://www.amazon.com/<wbr>Interactive-Applications-<wbr>using-Matplotlib-Benjamin/dp/<wbr>1783988843</a><br>
<br>
Tom<br>
</p>
</blockquote><p dir="auto">---<br>
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.<br>
<a href="https://www.avast.com/antivirus" target="_blank">https://www.avast.com/<wbr>antivirus</a><br>
<br>
______________________________<wbr>_________________<br>
Matplotlib-users mailing list<br>
<a href="mailto:Matplotlib-users@python.org" target="_blank">Matplotlib-users@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/matplotlib-<wbr>users</a></p>
</blockquote></div>
<div style="white-space:normal">
</div>
</div></div></div>
</div>

<br>______________________________<wbr>_________________<br>
Matplotlib-users mailing list<br>
<a href="mailto:Matplotlib-users@python.org">Matplotlib-users@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/matplotlib-<wbr>users</a><br>
<br></blockquote></div><br></div>