2017-06-20 203 views
0

我使用matplotlib來繪製來自對一組電子郵件進行某些分析的兩個圖表。 這裏是應該顯示兩個數字的腳本,而實際上它顯示三個數字。我該如何解決這個錯誤?matplotlib:plt.show()顯示三個數字

# Show the distribution of emails over the years 
ax = emails_df.groupby(emails_df['Date'].dt.year)['content'].count().plot() 
ax.set_xlabel('Year', fontsize=18) 
ax.set_ylabel('N emails', fontsize=18) 

f1 = plt.figure() 

# Show the distribution of emails over a week 
ax = emails_df.groupby(emails_df['Date'].dt.dayofweek)['content'].count().plot() 
ax.set_xlabel('Day of week', fontsize=18) 
ax.set_ylabel('N emails', fontsize=18) 

f2 = plt.figure() 

plt.show() 

回答

1

數字調用應該出現在地塊之前,而不是之後。你的代碼,你將有一個空白數字與上次plt.figure電話:

# figure 1 
ax = emails_df.groupby(emails_df['Date'].dt.year)['content'].count().plot() 
... 

# figure 2 
f1 = plt.figure() 
... 

# figure 3 
f2 = plt.figure() 

plt.show() 

修復此由前plot調用之前移動plt.figure電話。