You are reading an old version of the documentation (v3.0.3). For the latest version see https://matplotlib.org/stable/gallery/userdemo/simple_legend01.html
Version 3.0.3
matplotlib
Fork me on GitHub

Related Topics

Simple Legend01ΒΆ

../../_images/sphx_glr_simple_legend01_001.png
import matplotlib.pyplot as plt


plt.subplot(211)
plt.plot([1, 2, 3], label="test1")
plt.plot([3, 2, 1], label="test2")
# Place a legend above this subplot, expanding itself to
# fully use the given bounding box.
plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc='lower left',
           ncol=2, mode="expand", borderaxespad=0.)

plt.subplot(223)
plt.plot([1, 2, 3], label="test1")
plt.plot([3, 2, 1], label="test2")
# Place a legend to the right of this smaller subplot.
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.)

plt.show()

Keywords: matplotlib code example, codex, python plot, pyplot Gallery generated by Sphinx-Gallery