Reputation: 2934
Currently the area of the figure that gets saved by is fixed, so if I have the legend outside the figure, it gets cropped off, like that:
Is there a function in matplotlib that allows to save larger area than the standard area of the figure, so I can save my figure with the legend, like below?
Upvotes: 2
Views: 386
Reputation: 85432
bbox_inches='tight'
should do the trick:
from matplotlib import pyplot as plt
plt.savefig('figure.png', bbox_inches='tight')
bbox_inches
:Bbox in inches. Only the given portion of the figure is saved. If 'tight', try to figure out the tight bbox of the figure.
plt.plot(range(10))
plt.legend(['abc'], loc='upper right', bbox_to_anchor=(1.2, 0.9))
results in this png:
Upvotes: 2