
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/event_handling/pick_event_demo2.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_event_handling_pick_event_demo2.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_event_handling_pick_event_demo2.py:


=================
Pick event demo 2
=================

Compute the mean (mu) and standard deviation (sigma) of 100 data sets and plot
mu vs. sigma.  When you click on one of the (mu, sigma) points, plot the raw
data from the dataset that generated this point.

.. 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 18-54



.. image-sg:: /gallery/event_handling/images/sphx_glr_pick_event_demo2_001.png
   :alt: click on point to plot time series
   :srcset: /gallery/event_handling/images/sphx_glr_pick_event_demo2_001.png, /gallery/event_handling/images/sphx_glr_pick_event_demo2_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. code-block:: Python

    import matplotlib.pyplot as plt
    import numpy as np

    # Fixing random state for reproducibility
    np.random.seed(19680801)

    X = np.random.rand(100, 1000)
    xs = np.mean(X, axis=1)
    ys = np.std(X, axis=1)

    fig, ax = plt.subplots()
    ax.set_title('click on point to plot time series')
    line, = ax.plot(xs, ys, 'o', picker=True, pickradius=5)


    def onpick(event):

        if event.artist != line:
            return

        N = len(event.ind)
        if not N:
            return

        figi, axs = plt.subplots(N, squeeze=False)
        for ax, dataind in zip(axs.flat, event.ind):
            ax.plot(X[dataind])
            ax.text(.05, .9, f'mu={xs[dataind]:1.3f}\nsigma={ys[dataind]:1.3f}',
                    transform=ax.transAxes, va='top')
            ax.set_ylim(-0.5, 1.5)
        figi.show()


    fig.canvas.mpl_connect('pick_event', onpick)

    plt.show()


.. _sphx_glr_download_gallery_event_handling_pick_event_demo2.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: pick_event_demo2.ipynb <pick_event_demo2.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: pick_event_demo2.py <pick_event_demo2.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: pick_event_demo2.zip <pick_event_demo2.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
