You are reading documentation for the unreleased version of Matplotlib. Try searching for the released version of this page instead?
Version 2.1.1.post1120+g407a460
Fork me on GitHub

Related Topics

This Page

Color By y-valueΒΆ

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)

fig, ax = plt.subplots()
ax.plot(t, smiddle, t, slower, t, supper)

Gallery generated by Sphinx-Gallery