mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-11-19 09:00:59 +00:00
Plot continuous weekly seasonality with sub daily data (#1615)
* Check frequency of data * If sub-daily, use plot_seasonality() * Format xticks as weekdays for plot_seasonality() * Display 8 xticks for weekly component
This commit is contained in:
parent
40b170b95a
commit
ad53b428c3
1 changed files with 18 additions and 4 deletions
|
|
@ -150,6 +150,9 @@ def plot_components(
|
||||||
|
|
||||||
multiplicative_axes = []
|
multiplicative_axes = []
|
||||||
|
|
||||||
|
dt = m.history['ds'].diff()
|
||||||
|
min_dt = dt.iloc[dt.values.nonzero()[0]].min()
|
||||||
|
|
||||||
for ax, plot_name in zip(axes, components):
|
for ax, plot_name in zip(axes, components):
|
||||||
if plot_name == 'trend':
|
if plot_name == 'trend':
|
||||||
plot_forecast_component(
|
plot_forecast_component(
|
||||||
|
|
@ -158,9 +161,14 @@ def plot_components(
|
||||||
)
|
)
|
||||||
elif plot_name in m.seasonalities:
|
elif plot_name in m.seasonalities:
|
||||||
if plot_name == 'weekly' or m.seasonalities[plot_name]['period'] == 7:
|
if plot_name == 'weekly' or m.seasonalities[plot_name]['period'] == 7:
|
||||||
plot_weekly(
|
if min_dt < pd.Timedelta(days=1):
|
||||||
m=m, name=plot_name, ax=ax, uncertainty=uncertainty, weekly_start=weekly_start
|
plot_seasonality(
|
||||||
)
|
m=m, name=plot_name, ax=ax, uncertainty=uncertainty,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
plot_weekly(
|
||||||
|
m=m, name=plot_name, ax=ax, uncertainty=uncertainty, weekly_start=weekly_start
|
||||||
|
)
|
||||||
elif plot_name == 'yearly' or m.seasonalities[plot_name]['period'] == 365.25:
|
elif plot_name == 'yearly' or m.seasonalities[plot_name]['period'] == 365.25:
|
||||||
plot_yearly(
|
plot_yearly(
|
||||||
m=m, name=plot_name, ax=ax, uncertainty=uncertainty, yearly_start=yearly_start
|
m=m, name=plot_name, ax=ax, uncertainty=uncertainty, yearly_start=yearly_start
|
||||||
|
|
@ -389,11 +397,17 @@ 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)
|
||||||
xticks = pd.to_datetime(np.linspace(start.value, end.value, 7)
|
if name == 'weekly' and period > 1:
|
||||||
|
n_ticks = 8
|
||||||
|
else:
|
||||||
|
n_ticks = 7
|
||||||
|
xticks = pd.to_datetime(np.linspace(start.value, end.value, n_ticks)
|
||||||
).to_pydatetime()
|
).to_pydatetime()
|
||||||
ax.set_xticks(xticks)
|
ax.set_xticks(xticks)
|
||||||
if period <= 2:
|
if period <= 2:
|
||||||
fmt_str = '{dt:%T}'
|
fmt_str = '{dt:%T}'
|
||||||
|
elif name == 'weekly':
|
||||||
|
fmt_str = '{dt:%A}'
|
||||||
elif period < 14:
|
elif period < 14:
|
||||||
fmt_str = '{dt:%m}/{dt:%d} {dt:%R}'
|
fmt_str = '{dt:%m}/{dt:%d} {dt:%R}'
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue