Search code examples
pythonfacebook-graph-apigraphforecastingfacebook-prophet

Plotting only forecasted value on Facebook Prophet model Python


When I plot with facebook prophet model by the following code:

number_of_days_in_future = 20
future = m.make_future_dataframe(periods=number_of_days_in_future, freq="D") 
weekend = future[future['ds'].dt.dayofweek < 5  ]
prediction = m.predict(weekend)
m.plot(prediction)
plt.title("Prediction of Value")
plt.xlabel("Date")
plt.ylabel("Value")
plt.show()

It shows plotting from the beginning of historical data like below: Plotted

It's difficult to understand the value from the graph as it spans large range for Y-axis.

But if I forecast only for few days. It's easier to understand the value from Y-axis like this:

enter image description here

My questions are:

  1. Is there any way so that it doesn't span that large range? ( if we can ignore plotting the shadow part )
  2. Is there any way just to plot the tail forecasted part? ( I don't want to plot whole historical data )

Solution

  • I just found a way from fbprophet repository to fulfill my requirements.

    fig = m.plot(prediction)
    ax = fig.gca()
    # setting x limit. date range to plot
    ax.set_xlim(pd.to_datetime(['2020-08-19', '2020-08-25'])) 
    # we can ignore the shadow part by setting y limit
    ax.set_ylim([26, 29]) 
    

    The graph becomes clearer : enter image description here