def plotWeekly(dictframe, ax, uncertainty, weeklyStart, color='#0072B2'):
if ax is None:
figW = plt.figure(facecolor='w', figsize=(10, 6))
ax = figW.add_subplot(111)
else:
figW = ax.get_figure()
##
# Create a list of 7 days for the x axis of the plot
##
days = (pd.date_range(start='2017-01-01', periods=7) +
pd.Timedelta(days=weeklyStart))
##
# Find the weekday seasonality values for each weekday
##
weekdays = dictframe.ds.dt.weekday
ind = []
for weekday in range(7):
ind.append(max(weekdays[weekdays == weekday].index.tolist()))
##
# Plot only one weekday each
##
ax.plot(range(len(days)), dictframe['weekly'][ind], ls='-', c=color)
##
# Plot uncertainty if necessary
##
if uncertainty:
ax.fill_between(range(len(days)),dictframe['weekly_lower'][ind], dictframe['weekly_upper'][ind],color=color, alpha=0.2)
ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2)
ax.set_xticks(range(len(days)))
ax.set_xticklabels(dictframe['ds'][ind].dt.weekday_name)
ax.set_xlabel('Day of week')
ax.set_ylabel('weekly')
figW.tight_layout()
return figW
评论列表
文章目录