.. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_event_handling_pick_event_demo2.py: ================ Pick Event Demo2 ================ 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. .. image:: /gallery/event_handling/images/sphx_glr_pick_event_demo2_001.png :alt: click on point to plot time series :class: sphx-glr-single-img .. code-block:: default import numpy as np import matplotlib.pyplot as plt # 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 True N = len(event.ind) if not N: return True figi, axs = plt.subplots(N, squeeze=False) for ax, dataind in zip(axs.flat, event.ind): ax.plot(X[dataind]) ax.text(.05, .9, 'mu=%1.3f\nsigma=%1.3f' % (xs[dataind], ys[dataind]), transform=ax.transAxes, va='top') ax.set_ylim(-0.5, 1.5) figi.show() return True 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 :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pick_event_demo2.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pick_event_demo2.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature Keywords: matplotlib code example, codex, python plot, pyplot `Gallery generated by Sphinx-Gallery `_