cqc*_*991 2 python matplotlib mplot3d
如果我在 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')
Run Code Online (Sandbox Code Playgroud)
它将产生:
左侧有过多的空白。我想知道是否有可能摆脱它?
可能为时已晚,但我遇到了类似的问题,这是我为删除空白所做的工作:用于fig.subplot_adjust()
将左/右放在正常区域之外。在你的情况下,我发现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
Run Code Online (Sandbox Code Playgroud)