{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Figure/Axes enter and leave events\n\nIllustrate the figure and Axes enter and leave events by changing the\nframe colors on enter and leave.\n\n<div class=\"alert alert-info\"><h4>Note</h4><p>This example exercises the interactive capabilities of Matplotlib, and this\n    will not appear in the static documentation. Please run this code on your\n    machine to see the interactivity.\n\n    You can copy and paste individual parts, or download the entire example\n    using the link at the bottom of the page.</p></div>\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\n\n\ndef on_enter_axes(event):\n    print('enter_axes', event.inaxes)\n    event.inaxes.patch.set_facecolor('yellow')\n    event.canvas.draw()\n\n\ndef on_leave_axes(event):\n    print('leave_axes', event.inaxes)\n    event.inaxes.patch.set_facecolor('white')\n    event.canvas.draw()\n\n\ndef on_enter_figure(event):\n    print('enter_figure', event.canvas.figure)\n    event.canvas.figure.patch.set_facecolor('red')\n    event.canvas.draw()\n\n\ndef on_leave_figure(event):\n    print('leave_figure', event.canvas.figure)\n    event.canvas.figure.patch.set_facecolor('grey')\n    event.canvas.draw()\n\n\nfig, axs = plt.subplots(2, 1)\nfig.suptitle('mouse hover over figure or Axes to trigger events')\n\nfig.canvas.mpl_connect('figure_enter_event', on_enter_figure)\nfig.canvas.mpl_connect('figure_leave_event', on_leave_figure)\nfig.canvas.mpl_connect('axes_enter_event', on_enter_axes)\nfig.canvas.mpl_connect('axes_leave_event', on_leave_axes)\n\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.14.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}