{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Close event\n\nExample to show connecting events that occur when the figure closes.\n\n

Note

\n\nThis example exercises the interactive capabilities of Matplotlib, and this\nwill not appear in the static documentation. Please run this code on your\nmachine to see the interactivity.\n\nYou can copy and paste individual parts, or download the entire example\nusing the link at the bottom of the page.\n\n
\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n\n\ndef on_close(event):\n print('Closed Figure!')\n\nfig = plt.figure()\nfig.canvas.mpl_connect('close_event', on_close)\n\nplt.text(0.35, 0.5, 'Close Me!', dict(size=30))\nplt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.15" } }, "nbformat": 4, "nbformat_minor": 0 }