You are reading an old version of the documentation (v2.1.2). For the latest version see
Version 2.1.2
Fork me on GitHub


Related Topics

This Page

Legend using pre-defined labelsΒΆ

Defining legend labels with plots.

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.
fig, ax = plt.subplots()
ax.plot(a, c, 'k--', label='Model length')
ax.plot(a, d, 'k:', label='Data length')
ax.plot(a, c + d, 'k', label='Total message length')

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

# Put a nicer background color on the legend.

Total running time of the script: ( 0 minutes 0.021 seconds)

Gallery generated by Sphinx-Gallery