Minor simplification to weekly plotting logic

This commit is contained in:
Ben Letham 2020-08-17 17:40:01 -07:00
parent 2049217471
commit 9fb8f103d6

View file

@ -160,12 +160,10 @@ def plot_components(
plot_cap=plot_cap, plot_cap=plot_cap,
) )
elif plot_name in m.seasonalities: elif plot_name in m.seasonalities:
if plot_name == 'weekly' or m.seasonalities[plot_name]['period'] == 7: if (
if min_dt < pd.Timedelta(days=1): (plot_name == 'weekly' or m.seasonalities[plot_name]['period'] == 7)
plot_seasonality( and (min_dt == pd.Timedelta(days=1))
m=m, name=plot_name, ax=ax, uncertainty=uncertainty, ):
)
else:
plot_weekly( plot_weekly(
m=m, name=plot_name, ax=ax, uncertainty=uncertainty, weekly_start=weekly_start m=m, name=plot_name, ax=ax, uncertainty=uncertainty, weekly_start=weekly_start
) )
@ -397,10 +395,7 @@ def plot_seasonality(m, name, ax=None, uncertainty=True, figsize=(10, 6)):
df_y['ds'].dt.to_pydatetime(), seas[name + '_lower'], df_y['ds'].dt.to_pydatetime(), seas[name + '_lower'],
seas[name + '_upper'], color='#0072B2', alpha=0.2)] seas[name + '_upper'], color='#0072B2', alpha=0.2)]
ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2) ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2)
if name == 'weekly' and period > 1:
n_ticks = 8 n_ticks = 8
else:
n_ticks = 7
xticks = pd.to_datetime(np.linspace(start.value, end.value, n_ticks) xticks = pd.to_datetime(np.linspace(start.value, end.value, n_ticks)
).to_pydatetime() ).to_pydatetime()
ax.set_xticks(xticks) ax.set_xticks(xticks)