2016-07-27 136 views
0

如果我做出Matplotlib 3D繪圖:Matplotlib 3d plot:如何擺脫過多的空白空間?

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') 

它會產生:

enter image description here

左側有過多的空白。我想知道是否有可能擺脫它?

+0

你指的是軸內或圖內的軸的情節? – Aguy

+1

如果您單擊該圖並移動您的鼠標也會移動。如果將它在x軸上移動90度,則z標籤和z標記將位於另一側。我認爲過多的空白是爲了適應這種情況。 – DavidG

+0

@Aguy最左邊的數字'10',左邊的白色空間和黑色背景之間的空白。 – cqcn1991

回答

2

這可能太晚了,但我遇到了類似的問題,這裏是我做的刪除空白:使用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 

enter image description here