.. _pylab_examples-color_by_yvalue: pylab_examples example code: color_by_yvalue.py =============================================== .. plot:: /home/tcaswell/source/my_source/matplotlib/doc/mpl_examples/pylab_examples/color_by_yvalue.py :: # 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 = np.ma.masked_where(s < upper, s) slower = np.ma.masked_where(s > lower, s) smiddle = np.ma.masked_where(np.logical_or(s < lower, s > upper), s) plt.plot(t, slower, 'r', t, smiddle, 'b', t, supper, 'g') plt.show() Keywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)