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

Related Topics

This Page

Simple Legend02ΒΆ

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

line1, = ax.plot([1, 2, 3], label="Line 1", linestyle='--')
line2, = ax.plot([3, 2, 1], label="Line 2", linewidth=4)

# Create a legend for the first line.
first_legend = ax.legend(handles=[line1], loc=1)

# Add the legend manually to the current Axes.

# Create another legend for the second line.
ax.legend(handles=[line2], loc=4)

Gallery generated by Sphinx-Gallery