2014-03-12 27 views
1

我正在使用pandas matplotlib繪製dataFrame中的數據。 我正在做這樣的:pandas matplotlib調整大小和刪除標籤

df = pd.DataFrame({'type': dataFrame['Country'], labelName: 'Infant mort. rate'}) 
ax = df.plot(kind='bar',x= dataFrame['Country']) 
ax.set_ylabel('Infant mort. rate') 
ax.set_xlabel('Country') 
plt.show() 

enter image description here

我試圖讓右上角(「色藍」嬰兒病危率)。 去掉標籤,我想調整整個窗口的大小,以便我可以看到xlabel(現在它隱藏在底部的白線下) 我該怎麼做?

回答

2

首先明確地創建您的圖形和軸對象,在顯示圖之前將一些其他選項傳遞給df.plot(...)並調用fig.tight_layout()

import matplotlib.pyplot as plt 
import pandas as pd 
fig, ax = plt.subplots(figsize=(8,5)) 
df = pd.DataFrame({'type': dataFrame['Country'], labelName: 'Infant mort. rate'}) 
ax = df.plot(kind='bar', x=dataFrame['Country'], legend=False, ax=ax) 
ax.set_ylabel('Infant mort. rate') 
ax.set_xlabel('Country') 
fig.tight_layout() 
plt.show() 
+0

這很好,謝謝 –