Matplotlib automatic legend outside plot [duplicate]
问题 This question already has answers here : How to put the legend out of the plot (16 answers) Closed 2 years ago . I am trying to use the keyword bbox_to_anchor() in a matplotlib plot in Python. Here is a very basic plot that I have produced: import matplotlib.pyplot as plt x = [1,2,3] plt.subplot(211) plt.plot(x, label="test1") plt.plot([3,2,1], label="test2") plt.legend(bbox_to_anchor=(0, -0.15, 1, 0), loc=2, ncol=2, mode="expand", borderaxespad=0) plt.show() It is based on the example here: