Too much white space around graphs in 3d projection

When using 3d projection:

fig = plt.figure(figsize=(20,15))
ax = fig.gca(projection='3d')

and save the figure into png file, there is way too much white space from left right top and bottom, so when I want to add this graph into latex and use it in publication, I have to do post-processing of the image and remove unnecessary amount of blank space.

I don’t know why there is so much white space around 3-D projections. Presumably to allow them some room to be rotated. However, you can mitigate the problem during display using plt.figure(constrained_layout=True), and/or during print with fig.savefig(bbox_inches='tight').

That actually does work great!

fig = plt.figure(figsize=(20,15), constrained_layout=True)
ax = fig.gca(projection=‘3d’)

plt.savefig(‘1.png’, bbox_inches=‘tight’)