2017-08-07 66 views
2

當我從我的DataFrame繪製pyploy.subplots時,我沒有垂直線條。 數據框中指數看是:當使用matplotlib繪製網格時沒有垂直線

df_month.index 
DatetimeIndex(['2016-01-31', '2016-02-29', '2016-03-31', '2016-04-30', 
       '2016-05-31', '2016-06-30', '2016-07-31', '2016-08-31', 
       '2016-09-30', '2016-10-31', '2016-11-30', '2016-12-31'], 
       dtype='datetime64[ns]', freq='M') 

我需要爲每個行垂直線。 其實我的身材長相是(當我增加時間間隔,沒有爲每個月份的指數垂直線): enter image description here

這是它的一個代碼:

seaborn.set() 
fig, axis = plt.subplots(nrows=6, sharex=True) 

df_month.sum(axis=1).plot(ax=axis[0], marker = '.') 

axis[0].set_title('Sum of costs') 

for index, category in enumerate(df_month.columns.unique(), start=1): 
    df_month[category].sum(axis=1).plot(ax=axis[index], marker = '.') 
    axis[index].set_title(category) 

plt.show() 
+0

添加plt.axvline(I,YMIN = 0,YMAX = 1),其中i必須由幾個月來代替 – 2Obe

回答

0

你要繪製的網格線單獨爲每個軸的次要和主要刻度對象ax用命令:

ax.grid(b='on', which='major', color='k', linewidth=.5) 
ax.grid(b='on', which='minor', color='k', linewidth=.25) 

你必須在一個週期內執行這個代碼在所有軸的次要情節的對象。

尋找更多的信息在這裏:https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.grid.html