[英]plotting in groups of 2 with pandas in a for loop
所以我正在嘗試做標題所說的,這是我的代碼
for accountId in df["accountid"].unique():
df1 = df.loc[df["accountid"] == accountId]
df1 = df1.set_index(df1['dayCreate'])
df1.sort_index(inplace = True)
df1 = df1.filter(['isRift', 'isARAM'])
df1 = df1.resample('D').sum()
df1 = df1.asfreq('D', fill_value = 0)
df2 = df1.rolling(7).mean()
ax1 = df2.plot.area(figsize=(15,7), grid = True, stacked=False, title = "Rolling Window 7 days", legend = True, ylim = (0,8))
ax2 = df1.plot(figsize=(15,7), grid = True, title = "Amount of Games Played", legend = True)
ax1.xaxis.set_major_locator(mdates.DayLocator(interval=7))
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
ax1.tick_params(axis = 'x', labelrotation=45)
ax2.xaxis.set_major_locator(mdates.DayLocator(interval=7))
ax2.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
ax2.tick_params(axis = 'x', labelrotation=45)
so my current code plots each plot individually, but I want to group my rolling window plot and games played plot to be two sperate plot but it will select as one figure, so two plots in a subplot.
同樣出於某種原因,我的 x 軸在日期旁邊有一些額外的數字。
您可以將每個子圖ax
傳遞給df.plot
命令,如本答案所示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.