Avec le code ci-dessous, j'ai produit un chiffre que je voudrais sauvegarder en pdf. J'utilise savefig
commande:Découper l'espace blanc dans un tracé pdf en 3D (savefig), quand bbox_inches = 'tight' et pad_inches n'ont pas l'effet désiré
fig.savefig("Surface_I.pdf")
Le fichier pdf contient beaucoup d'espace blanc dans left
et up
:
fig.savefig("Surface_I.pdf", bbox_inches='tight')
solution découpe un peu d'information x
et z
, sans enlever trop d'espace de left
et top
:
La solution fig.savefig("Surface_I.pdf", bbox_inches='tight', pad_inches=0.3)
ajoute un peu d'espace, fixer l'info juste enlevé:
mais il y a encore trop de place dans left
et top
.
Comment est-ce que je pourrais enlever, ou couper, tous ces blancs left
et top
du pdf?
Note: toutes ces photos sont des captures d'écran du pdf généré.
code:
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
# Function:
z_fit = a0 + a1*yy + a2*xx + a3*yy**2 + a4*xx**2 + a5*xx*yy
# Parameters:
a0 = -941.487789948
a1 = 0.0146881652963
a2 = -2.53533353374e-05
a3 = -9.64343252786e-05
a4 = -2.47416662598e-08
a5 = 3.77136886946e-07
x_mesh = np.linspace(10.0000000000000, 2000.0000000000000, 20)
y_mesh = np.linspace(-4.4119598462100, 10.8557347078000, 20)
xx, yy = np.meshgrid(x_mesh, y_mesh)
# Plot the function
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_surface(xx, yy, z_fit, color='b', alpha=0.5)
ax.set_xlabel('\nx')
ax.set_ylabel('y')
ax.set_zlabel('\nzzzzz zzz', linespacing=3)
ax.set_title('\n\nSurface I', linespacing=3)
xlabels=[0, 250, 500, 750, 1000, 1250, 1500, 1750, 2000]
ax.set_xticklabels(xlabels,rotation=90,
verticalalignment='baseline',#)#,
horizontalalignment='left')
ylabels = [-4, -2, 0, 2, 4, 6, 8, 10]
ax.set_yticklabels(ylabels,rotation=0,
verticalalignment='baseline')#,
# horizontalalignment='left')
fig.savefig("Surface_I.pdf", bbox_inches='tight', pad_inches=0.3)
Je pense que ce que vous voulez est de définir votre propre boîte englobante comme indiqué dans la réponse par tom en [cette question] (https://stackoverflow.com/questions/41225293/remove-white-spaces-in-axes3d-matplotlib). Peut-être même suffit-il d'ajuster les paramètres du sous-schéma comme dans [cette question] (https://stackoverflow.com/questions/38604100/matplotlib-3d-plot-how-to-get-rid-of-the-excessive-white- espace? noredirect = 1 & lq = 1) – ImportanceOfBeingErnest