You are reading an old version of the documentation (v1.4.3). For the latest version see https://matplotlib.org/stable/

We're updating the default styles for Matplotlib 2.0

Learn what to expect in the new updates

matplotlib

Previous topic

pylab_examples example code: stem_plot.py

Next topic

pylab_examples example code: stix_fonts_demo.py

This Page

pylab_examples example code: step_demo.pyΒΆ

(Source code, png, hires.png, pdf)

../../_images/step_demo.png
import numpy as np
from numpy import ma
from matplotlib.pyplot import step, legend, xlim, ylim, show

x = np.arange(1, 7, 0.4)
y0 = np.sin(x)
y = y0.copy() + 2.5

step(x, y, label='pre (default)')

y -= 0.5
step(x, y, where='mid', label='mid')

y -= 0.5
step(x, y, where='post', label='post')

y = ma.masked_where((y0>-0.15)&(y0<0.15), y - 0.5)
step(x,y, label='masked (pre)')

legend()

xlim(0, 7)
ylim(-0.5, 4)

show()

Keywords: python, matplotlib, pylab, example, codex (see Search examples)