diff --git a/python/fbprophet/plot.py b/python/fbprophet/plot.py index 7036594..db739a2 100644 --- a/python/fbprophet/plot.py +++ b/python/fbprophet/plot.py @@ -150,6 +150,9 @@ def plot_components( multiplicative_axes = [] + dt = m.history['ds'].diff() + min_dt = dt.iloc[dt.values.nonzero()[0]].min() + for ax, plot_name in zip(axes, components): if plot_name == 'trend': plot_forecast_component( @@ -158,9 +161,14 @@ def plot_components( ) elif plot_name in m.seasonalities: if plot_name == 'weekly' or m.seasonalities[plot_name]['period'] == 7: - plot_weekly( - m=m, name=plot_name, ax=ax, uncertainty=uncertainty, weekly_start=weekly_start - ) + if min_dt < pd.Timedelta(days=1): + 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: plot_yearly( 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'], seas[name + '_upper'], color='#0072B2', 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() ax.set_xticks(xticks) if period <= 2: fmt_str = '{dt:%T}' + elif name == 'weekly': + fmt_str = '{dt:%A}' elif period < 14: fmt_str = '{dt:%m}/{dt:%d} {dt:%R}' else: