File: step.py

package info (click to toggle)
mplcursors 0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 400 kB
  • sloc: python: 1,915; makefile: 14; sh: 9
file content (28 lines) | stat: -rw-r--r-- 656 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Step plots
==========

A selection on a step plot holds precise information on the x and y position
in the ``sel.index`` attribute.
"""

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()