Making bbox_inches="tight" work when using multiple 3d plots

30 Views Asked by At

I am trying to figure out how to make a tight box around my 3 plots to use it in a Latex document. I think it has to do with the 3d plots but I am not sure why this happens and what to do.

#Load data

fig = plt.figure(figsize=plt.figaspect(1/3))


ax = fig.add_subplot(1, 3, 1, projection='3d')
Fs_plot = ax.plot_surface(zs_mesh, Losss_mesh, TDs, cmap="viridis", lw=0.1, rstride=1, cstride=1, rasterized=True)  
ax.plot_wireframe(zs_mesh, Losss_mesh, TDs, rstride=int(len(zs)/10), cstride=int(len(Losss)/10), color='black', linewidth=0.2)
ax.set_xlabel('$z$', fontsize=15, labelpad=-2)
ax.set_ylabel('Loss', fontsize=15, labelpad=2)
ax.zaxis.set_rotate_label(False) 
ax.set_zlabel(r'$D(\rho_\mathrm{TMSG}(\epsilon,z),\rho_\mathrm{SMSV}(z))$', fontsize=15, labelpad=-2, rotation=90)
ax.view_init(elev=25., azim=-135)
#ax.set_title('Trace distance', fontsize=15)
ax.tick_params(axis="x", pad=-3)
ax.tick_params(axis="y", pad=-3)
ax.tick_params(axis="z", pad=-2)
# make 2nd plot in same way (left out for readability)-2)

# make 3rd plot in same way (left out for readability)

plt.savefig(path, transparent=True, bbox_inches='tight')

Image created using the "right" flag

enter image description here

The pdf I created is cut off even though i used the bbox_inches="tight" flag. Any ideas how to fix it?

Ps: the image i created is not pdf cause I didnt find any upload option for pdf. So adjusting the dpi is not a solution for me.

I tried using tight_layout as well, but no...

0

There are 0 best solutions below