0

I want to plot something with the legend outside the figure. I am using

 legend(bbox_to_anchor=(1.2, 1))

To position the legend and then I have to do

 tight_layout()

To make sure the plot is complete when saved to a file.

Unfortunately, tight_layout pushes the legend into the figure no matter what values I put in the legend function. Is there any other way to make sure the legend is not touching the figure?

Soerendip
  • 7,684
  • 15
  • 61
  • 128
  • A lot about legend outside axes is found in [this answer](https://stackoverflow.com/a/43439132/4124317). I do not understand the problem here, but maybe it would become clearer when using the notions "figure" and "axes" [correctly](https://matplotlib.org/3.1.0/tutorials/introductory/usage.html#parts-of-a-figure)? – ImportanceOfBeingErnest Jun 03 '19 at 19:19
  • I'm not sure if this will solve your problem, but you could try`plt.savefig('filename.png', bbox_inches='tight')` without calling `tight_layout` when you save the figure. You can also use the `pad_inches` parameter if the legend is cut off. – iamchoosinganame Jun 03 '19 at 19:30

0 Answers0