.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/step.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_step.py: Step plots ========== A selection on a step plot holds precise information on the x and y position in the ``sel.index`` attribute. .. GENERATED FROM PYTHON SOURCE LINES 8-29 .. image-sg:: /examples/images/sphx_glr_step_001.png :alt: step :srcset: /examples/images/sphx_glr_step_001.png :class: sphx-glr-single-img .. code-block:: Python from matplotlib import pyplot as plt import mplcursors import numpy as np fig, axs = plt.subplots(4, sharex=True, sharey=True) np.random.seed(42) xs = np.arange(5) ys = np.random.rand(5) axs[0].plot(xs, ys, "-o") axs[1].plot(xs, ys, "-o", drawstyle="steps-pre") axs[2].plot(xs, ys, "-o", drawstyle="steps-mid") axs[3].plot(xs, ys, "-o", drawstyle="steps-post") for ax in axs: ax.label_outer() mplcursors.cursor().connect( "add", lambda sel: sel.annotation.set_text(format(sel.index, ".2f"))) plt.show() .. _sphx_glr_download_examples_step.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: step.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: step.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_