.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/event_handling/close_event.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. 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_gallery_event_handling_close_event.py: =========== Close Event =========== Example to show connecting events that occur when the figure closes. .. note:: This example exercises the interactive capabilities of Matplotlib, and this will not appear in the static documentation. Please run this code on your machine to see the interactivity. You can copy and paste individual parts, or download the entire example using the link at the bottom of the page. .. GENERATED FROM PYTHON SOURCE LINES 16-27 .. image-sg:: /gallery/event_handling/images/sphx_glr_close_event_001.png :alt: close event :srcset: /gallery/event_handling/images/sphx_glr_close_event_001.png, /gallery/event_handling/images/sphx_glr_close_event_001_2_00x.png 2.00x :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt def on_close(event): print('Closed Figure!') fig = plt.figure() fig.canvas.mpl_connect('close_event', on_close) plt.text(0.35, 0.5, 'Close Me!', dict(size=30)) plt.show() .. _sphx_glr_download_gallery_event_handling_close_event.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: close_event.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: close_event.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_