You are reading an old version of the documentation (v2.0.0). For the latest version see


This Page

pylab_examples example code: color_by_yvalue.pyΒΆ

(Source code, png, pdf)

# use masked arrays to plot a line with different colors by y-value
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2*np.pi*t)

upper = 0.77
lower = -0.77

supper = < upper, s)
slower = > lower, s)
smiddle = < lower, s > upper), s)

plt.plot(t, smiddle, t, slower, t, supper)

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