You are reading an old version of the documentation (v1.5.0). For the latest version see

We're updating the default styles for Matplotlib 2.0

Learn what to expect in the new updates


Previous topic

pylab_examples example code:

Next topic

pylab_examples example code:

This Page

pylab_examples example code: color_demo.pyΒΆ

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

#!/usr/bin/env python
matplotlib gives you 4 ways to specify colors,

    1) as a single letter string, ala MATLAB

    2) as an html style hex string or html color name

    3) as an R,G,B tuple, where R,G,B, range from 0-1

    4) as a string representing a floating point number
       from 0 to 1, corresponding to shades of gray.

See help(colors) for more info.
import matplotlib.pyplot as plt
import numpy as np

plt.subplot(111, axisbg='darkslategray')
#subplot(111, axisbg='#ababab')
t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2*np.pi*t)
plt.plot(t, s, 'y')
plt.xlabel('time (s)', color='r')
plt.ylabel('voltage (mV)', color='0.5')  # grayscale color
plt.title('About as silly as it gets, folks', color='#afeeee')

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