39

After adding

bbox_inches="tight"

to an invocation of plt.savefig that has worked for several years, I get

/usr/local/lib/python2.7/site-packages/matplotlib/figure.py:1744: UserWarning:

This figure includes Axes that are not compatible with tight_layout, so its results might be incorrect

The figure in question appears to work (without truncation of annotations now), but I wonder what this error could mean and whether there's anything obvious or known (without digging deep into complex figure code) that I can do to address it.

Is there some known or common cause for this that I should look for in my code?

Community
  • 1
  • 1
orome
  • 45,163
  • 57
  • 202
  • 418
  • could you add the code you are using to generate the graph? I just had a look around it it appears to be an issues with adding additional axis or hidden axis linked to colorbars – Wokpak Jul 02 '16 at 10:02
  • 1
    You could have a look at [Position colorbar inside figure](http://stackoverflow.com/questions/18211967/position-colorbar-inside-figure) thread which is about a similar issue faced with plotting colorbars along with subplots. This warning occurs if you have axes in your plots that aren't subplots. Eg: colorbar axis. The colorbar axis gets overlapped alongwith one of the subplots while rendering as a result. – Nickil Maveli Jul 30 '16 at 16:52

1 Answers1

41

In my experience, plt.tight_layout doesn't always work but plt.savefig('fig.png',bbox_inches='tight') does. In addition, you don't need the former after using the latter and I have come to the conclusion after some pretty extensive testing of it.

theletz
  • 1,713
  • 2
  • 16
  • 22
jimh
  • 1,651
  • 2
  • 15
  • 28