Text of discourse.matplotlib.org › t › mouse-cursor-coordinates › 19764 as Styx crawled it on Nov 20, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

mouse cursor coordinates - matplotlib-users - Matplotlib

mouse cursor coordinates Community matplotlib-users grivet1 May 30, 2016, 10:17am 1 Hello, I want to retrieve the mouse cursor coordinates when i click inside a figure. I have tried a variety ef example programs, such as from pylab import * fig = plt.figure() ax = fig.add_subplot(111) ax.plot(np.random.rand(10)) def onclick(event): print("button=%d, x=%d, y=%d, xdata=%f, ydata=%f" %( event.button, event.x, event.y, event.xdata, event.ydata)) cid = fig.canvas.mpl_connect('button_press_event', onclick) ax.set_title("click on figure") show() The figure gets plotted, then nothing happens: the program simply ends and focus retruns to the IPython console.

I am using distribution Anaconda/Python35/Spyder under Win7-64. What did I miss ? Thank you for your help, JP Grivet fiolj May 30, 2016, 12:36pm 2 It works well in my system (linux gentoo) with ipython-4.0.3, python-2.7.10 and python-3.4.3. Did you try running it outside spyder? May be save it into a file (test_cursor.py) and run it directly from a system console to see if the problem is with spyder. Anyway, I am not very experienced.

May be someone else may have a better advice. Regards, Juan ··· On 30/05/16 07:17, grivet wrote: Hello, I want to retrieve the mouse cursor coordinates when i click inside a figure. I have tried a variety ef example programs, such as from pylab import * fig = plt.figure() ax = fig.add_subplot(111) ax.plot(np.random.rand(10)) def onclick(event): print("button=%d, x=%d, y=%d, xdata=%f, ydata=%f" %( event.button, event.x, event.y, event.xdata, event.ydata)) cid = fig.canvas.mpl_connect('button_press_event', onclick) ax.set_title("click on figure") show() The figure gets plotted, then nothing happens: the program simply ends and focus retruns to the IPython console.

I am using distribution Anaconda/Python35/Spyder under Win7-64. What did I miss ? Thank you for your help, JP Grivet _______________________________________________ Matplotlib-users mailing list Matplotlib-users at python.org Matplotlib-users Info Page grivet1 May 30, 2016, 2:40pm 3 Le 30/05/2016 ? 14:36, Juan a ?crit : It works well in my system (linux gentoo) with ipython-4.0.3, python-2.7.10 and python-3.4.3. Did you try running it outside spyder?

May be save it into a file (test_cursor.py) and run it directly from a system console to see if the problem is with spyder. Anyway, I am not very experienced. May be someone else may have a better advice. Regards, Juan Hello, I want to retrieve the mouse cursor coordinates when i click inside a figure. I have tried a variety ef example programs, such as from pylab import * fig = plt.figure() ax = fig.add_subplot(111) ax.plot(np.random.rand(10)) def onclick(event): print("button=%d, x=%d, y=%d, xdata=%f, ydata=%f" %( event.button, event.x, event.y, event.xdata, event.ydata)) cid = fig.canvas.mpl_connect('button_press_event', onclick) ax.set_title("click on figure") show() The figure gets plotted, then nothing happens: the program simply ends and focus retruns to the IPython console.

I am using distribution Anaconda/Python35/Spyder under Win7-64. What did I miss ? Thank you for your help, JP Grivet _______________________________________________ Matplotlib-users mailing list Matplotlib-users at python.org Matplotlib-users Info Page Juan, It seems you are right; all the examples I had tried unsuccessfully before work OK when launched in command window . What should I do next ? JP Grivet ··· On 30/05/16 07:17, grivet wrote: fiolj May 30, 2016, 3:11pm 4 Ok, I do not use spyder so I may be wrong, but it looks that it works if in the preferences windows (Tools -> Preferences) in the option: "IPython console" In the tab: "Graphics" you select the Backend: "Automatic" You probably have to restart spyder for it to work.

Regards, Juan ··· On 30/05/16 11:40, grivet wrote: Le 30/05/2016 ? 14:36, Juan a ?crit : It works well in my system (linux gentoo) with ipython-4.0.3, python-2.7.10 and python-3.4.3. Did you try running it outside spyder? May be save it into a file (test_cursor.py) and run it directly from a system console to see if the problem is with spyder. Anyway, I am not very experienced. May be someone else may have a better advice.

Regards, Juan On 30/05/16 07:17, grivet wrote: Hello, I want to retrieve the mouse cursor coordinates when i click inside a figure. I have tried a variety ef example programs, such as from pylab import * fig = plt.figure() ax = fig.add_subplot(111) ax.plot(np.random.rand(10)) def onclick(event): print("button=%d, x=%d, y=%d, xdata=%f, ydata=%f" %( event.button, event.x, event.y, event.xdata, event.ydata)) cid = fig.canvas.mpl_connect('button_press_event', onclick) ax.set_title("click on figure") show() The figure gets plotted, then nothing happens: the program simply ends and focus retruns to the IPython console.

I am using distribution Anaconda/Python35/Spyder under Win7-64. What did I miss ? Thank you for your help, JP Grivet _______________________________________________ Matplotlib-users mailing list Matplotlib-users at python.org Matplotlib-users Info Page Juan, It seems you are right; all the examples I had tried unsuccessfully before work OK when launched in command window . What should I do next ? JP Grivet grivet1 May 31, 2016, 9:33am 5 Right again!

A separate window is now created and I can click inside and retrieve the pointer coordinates. Thanks a lot, JP Grivet ··· Ok, I do not use spyder so I may be wrong, but it looks that it works if in the preferences windows (Tools -> Preferences) in the option: "IPython console" In the tab: "Graphics" you select the Backend: "Automatic" You probably have to restart spyder for it to work. Regards, Juan On 30/05/16 11:40, grivet wrote: Le 30/05/2016 ?

14:36, Juan a ?crit : It works well in my system (linux gentoo) with ipython-4.0.3, python-2.7.10 and python-3.4.3. Did you try running it outside spyder? May be save it into a file (test_cursor.py) and run it directly from a system console to see if the problem is with spyder. Anyway, I am not very experienced. May be someone else may have a better advice. Regards, Juan On 30/05/16 07:17, grivet wrote: Hello, I want to retrieve the mouse cursor coordinates when i click inside a figure.

I have tried a variety ef example programs, such as from pylab import * fig = plt.figure() ax = fig.add_subplot(111) ax.plot(np.random.rand(10)) def onclick(event): print("button=%d, x=%d, y=%d, xdata=%f, ydata=%f" %( event.button, event.x, event.y, event.xdata, event.ydata)) cid = fig.canvas.mpl_connect('button_press_event', onclick) ax.set_title("click on figure") show() The figure gets plotted, then nothing happens: the program simply ends and focus retruns to the IPython console.

I am using distribution Anaconda/Python35/Spyder under Win7-64. What did I miss ? Thank you for your help, JP Grivet _______________________________________________ Matplotlib-users mailing list Matplotlib-users at python.org Matplotlib-users Info Page Juan, It seems you are right; all the examples I had tried unsuccessfully before work OK when launched in command window . What should I do next ? JP Grivet grivet1 June 3, 2016, 10:12am 6 Hello, I would like to go further and, in fact, do the following: repeat n times click inside a figure retrieve and store the pointer coordinates show a mark (or circle or whatever) at this point Thank you for your suggestions JP Grivet ··· Right again!

A separate window is now created and I can click inside and retrieve the pointer coordinates. Thanks a lot, JP Grivet Ok, I do not use spyder so I may be wrong, but it looks that it works if in the preferences windows (Tools -> Preferences) in the option: "IPython console" In the tab: "Graphics" you select the Backend: "Automatic" You probably have to restart spyder for it to work. Regards, Juan tacaswell June 3, 2016, 12:30pm 7 See the spline example in this gist multimodal mpl tutorial · GitHub and http://matplotlib.org/users/event_handling.html The trick is to register an instance met

The rest of this page is on the live site.