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

api example code: joinstyle.py

Next topic

api example code: line_with_text.py

This Page

api example code: legend_demo.pyΒΆ

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

../../_images/legend_demo1.png
import numpy as np
import matplotlib.pyplot as plt

# Make some fake data.
a = b = np.arange(0,3, .02)
c = np.exp(a)
d = c[::-1]

# Create plots with pre-defined labels.
plt.plot(a, c, 'k--', label='Model length')
plt.plot(a, d, 'k:', label='Data length')
plt.plot(a, c+d, 'k', label='Total message length')

legend = plt.legend(loc='upper center', shadow=True, fontsize='x-large')

# Put a nicer background color on the legend.
legend.get_frame().set_facecolor('#00FFCC')

plt.show()

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