.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "11_demos\python_packages\matplotlib\demo_matplotlib_events.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_11_demos_python_packages_matplotlib_demo_matplotlib_events.py: Events ========= .. GENERATED FROM PYTHON SOURCE LINES 5-40 .. image-sg:: /11_demos/python_packages/matplotlib/images/sphx_glr_demo_matplotlib_events_001.png :alt: demo matplotlib events :srcset: /11_demos/python_packages/matplotlib/images/sphx_glr_demo_matplotlib_events_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 12 | .. code-block:: Python import matplotlib.pyplot as plt import numpy as np fig, ax = plt.subplots() ax.plot(np.random.rand(10)) def onclick(event): print( "%s click: button=%d, x=%d, y=%d, xdata=%f, ydata=%f" % ( "double" if event.dblclick else "single", event.button, event.x, event.y, event.xdata, event.ydata, ) ) def onfigureenter(event): if event.x and event.y: print( "onfigureenter: x={:f}, y={:f}, inaxes={}".format( event.x, event.y, str(event.inaxes) ) ) else: print("onfigureenter: x=, y=, inaxes=%s" % str(event.inaxes)) cid = fig.canvas.mpl_connect("button_press_event", onclick) fig.canvas.mpl_connect("figure_enter_event", onfigureenter) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.039 seconds) .. _sphx_glr_download_11_demos_python_packages_matplotlib_demo_matplotlib_events.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_matplotlib_events.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_matplotlib_events.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_matplotlib_events.zip `