def plot_daily_inf_res(df, symbols=[], plot_top=0):
df = df.copy()
# data_nasdaq_top_100_preprocessed_merge.groupby('SYMBOL')
years = mdates.YearLocator() # every year
months = mdates.MonthLocator() # every month
years_fmt = mdates.DateFormatter('%Y')
df['max_pmi_is'] = df[[col for col in df.columns if 'pmi_is' in col]].max(axis=1)
if len(symbols) > 0:
df = df.loc[symbols]
if plot_top > 0:
idx = df.groupby('SYMBOL')['max_pmi_is'].max().sort_values(ascending=False).index[:plot_top].values
print idx
df = df.loc[list(idx)]
# df = df.reindex(index=idx)
fig, ax = plt.subplots(figsize=(15,5))
for key, grp in df.groupby('SYMBOL'):
print "key", key
# grp.reset_index()
# print grp.DATE
ax.plot(grp.DATE.reset_index(drop=True), grp['max_pmi_is'], label=key)
# grp['D'] = pd.rolling_mean(grp['B'], window=5)
# plt.plot(grp['D'], label='rolling ({k})'.format(k=key))
# datemin = (df.DATE.min().year)
# datemax = (df.DATE.max().year + 1)
# print datemin, datemax
# ax.set_xlim(datemin, datemax)
ax.set_ylim(0, 500)
plt.legend(loc='best')
plt.ylabel('PMI IS (-2)')
fig.autofmt_xdate()
plt.show()
评论列表
文章目录