{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Pick event demo 2\n\nCompute the mean (mu) and standard deviation (sigma) of 100 data sets and plot\nmu vs. sigma.  When you click on one of the (mu, sigma) points, plot the raw\ndata from the dataset that generated this point.\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\nimport numpy as np\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\nX = np.random.rand(100, 1000)\nxs = np.mean(X, axis=1)\nys = np.std(X, axis=1)\n\nfig, ax = plt.subplots()\nax.set_title('click on point to plot time series')\nline, = ax.plot(xs, ys, 'o', picker=True, pickradius=5)\n\n\ndef onpick(event):\n\n    if event.artist != line:\n        return\n\n    N = len(event.ind)\n    if not N:\n        return\n\n    figi, axs = plt.subplots(N, squeeze=False)\n    for ax, dataind in zip(axs.flat, event.ind):\n        ax.plot(X[dataind])\n        ax.text(.05, .9, f'mu={xs[dataind]:1.3f}\\nsigma={ys[dataind]:1.3f}',\n                transform=ax.transAxes, va='top')\n        ax.set_ylim(-0.5, 1.5)\n    figi.show()\n\n\nfig.canvas.mpl_connect('pick_event', onpick)\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
}