0

I'd like some assistance in using a more granular time-series in my Prophet forecast plots, specifically an Hour grain on the x-axis.
My data is aggregated for each Hour of the day. In addition to the aggregated data, I create the necessary Prophet variables with:

ads_mod['y'] = ads_mod[target1]
ads_mod['ds'] = ads_mod['hour']

I then start the modeling process:

m = Prophet(interval_width=interval_width)
m.add_seasonality(name='hourly', period=1, fourier_order=30)
m.fit(ads_mod)
future = m.make_future_dataframe(periods=1,freq='H') 
forecast = m.predict(future)

I plot the Forecast with:

fig = m.plot(forecast)

I have reviewed the actual code in the plot function and tried a variety of modifications to display the hour along with date(i.e., datetime value) on the x-axis, without success. In particular, I looked at the date transform:

fcst_t = fcst['ds'].dt.to_pydatetime()

After the transform, I see my data is now in the following format, with the Hour still included. A fragment of the plot is below and you see that on the x-axis the date(i.e., YYYY,MM,DD) is the only value displayed:

fcst_t[:10]
Out[277]: 
array([datetime.datetime(2019, 12, 2, 0, 0),
       datetime.datetime(2019, 12, 2, 1, 0),
       datetime.datetime(2019, 12, 2, 2, 0),
       datetime.datetime(2019, 12, 2, 3, 0),
       datetime.datetime(2019, 12, 2, 4, 0),
       datetime.datetime(2019, 12, 2, 5, 0),
       datetime.datetime(2019, 12, 2, 6, 0),
       datetime.datetime(2019, 12, 2, 7, 0),
       datetime.datetime(2019, 12, 2, 8, 0),
       datetime.datetime(2019, 12, 2, 9, 0)], dtype=object)

Plot Fragment

EcoWarrior
  • 571
  • 1
  • 4
  • 12

1 Answers1

0
import matplotlib.dates as mdates

.... additional plot code here......

hours = mdates.HourLocator(interval = 1)
h_fmt = mdates.DateFormatter('%Y-%m-%d %H:%M:%S')
ax.xaxis.set_major_locator(hours)
ax.xaxis.set_major_formatter(h_fmt)

Here is the link: https://urldefense.com/v3/https://stackoverflow.com/questions/48790378/how-to-get-ticks-every-hour;!!M-nmYVHPHQ!cfpmWmLR0J5OMTJIH0aiEwrHWzsnD7pHJSBdVXxRTcAMK6mQ3v8K-FudC7uC6RN78uhTDCkD$

EcoWarrior
  • 571
  • 1
  • 4
  • 12