Matplotlib 3d plot:如何去掉多余的白色space?

Matplotlib 3d plot: how to get rid of the excessive white space?

如果我在 Matplotlib 中绘制 3d 图:

from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')

x_labels = [10,20,30]
x = [1,2,3,4]
y = [3,1,5,1]
legend = False

for label in x_labels:
    x_3d = label*np.ones_like(x)
    ax.plot(x_3d, x, y, color='black', label='GMM')
    if legend == False:
        ax.legend()
        legend = True

ax.set_zlabel('test')

它将产生:

左侧白色过多space。我想知道是否可以摆脱它?

可能为时已晚,但我遇到了类似的问题,这是我去除白色 space 的方法:使用 fig.subplot_adjust() 将 left/right 置于正常区域之外。在你的情况下,我发现 fig.subplot_adjust(left=-0.11) 给出了一个合理的结果。

完整代码如下:

from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()  
ax = fig.gca(projection='3d')

x_labels = [10,20,30]
x = [1,2,3,4]
y = [3,1,5,1]
legend = False

for label in x_labels:
    x_3d = label*np.ones_like(x)
    ax.plot(x_3d, x, y, color='black', label='GMM')
    if legend == False:
        ax.legend()
        legend = True

ax.set_zlabel('test')

fig.tight_layout()
fig.subplots_adjust(left=-0.11)  # plot outside the normal area