1

I have the same problem as this guy here, so I want to put my legend outside the plot, but the savefig does not work. Additionally, I am working with the subplots environment. So let me phrase the problem here as general as possible:

 fig, axarr = plt.subplots(n,m)
 #... (plotting)...
 axarr[k,l].legend(loc=(X,Y)) # X and Y such that outside of plot
 plt.savefig("test.pdf")

By the way, for me the keyword 'bbox_inches' does not work.

Community
  • 1
  • 1
varantir
  • 6,624
  • 6
  • 36
  • 57

1 Answers1

1

You can try this it may work

lgd = axarr[k,l].legend(loc=(X,Y)) # X and Y such that outside of plot
plt.savefig("test.pdf", bbox_inches='tight', bbox_extra_artists=(lgd,))
GWW
  • 43,129
  • 11
  • 115
  • 108