Matplotlib 3D图:如何摆脱多余的空白? [英] Matplotlib 3d plot: how to get rid of the excessive white space?
本文介绍了Matplotlib 3D图:如何摆脱多余的空白?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在Matplotlib中绘制3d图:
If I make a 3d plot in Matplotlib:
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')
它将产生:
左侧有过多的空白.我想知道是否有可能摆脱它?
The left side have excessive white space. I want to know if it is possible to get rid of it?
推荐答案
可能为时已晚,但是我遇到了类似的问题,这是我删除空白的方法:使用fig.subplot_adjust()
将左/右放在外面正常区域.在您的情况下,我发现fig.subplot_adjust(left=-0.11)
给出了合理的结果.
It's probably too late, but I came across similar problems and here is what I did to remove the white space: use fig.subplot_adjust()
to put left/right outside the normal region. In your case I found fig.subplot_adjust(left=-0.11)
gives a reasonable result.
下面的完整代码:
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
这篇关于Matplotlib 3D图:如何摆脱多余的空白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文