0

I made a time series model using prophet and I want to find the exact date of the maximum of the yearly trend revealed by the plot made by the m.plot_components(forecast) function.

However I'm not sure how to extract it from the plot. from prophets examples page:

import pandas as pd
from fbprophet import Prophet
df = pd.read_csv('../examples/example_wp_log_peyton_manning.csv')
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=365)
forecast = m.predict(future)
fig2 = m.plot_components(forecast)

fig2.axis[2] is an 'AxesSubplot' object and it comes from a 'matplotlib.figure.Figure' (fig2). How do I get out the arrays that make up the line inside that subplot object?

Travasaurus
  • 601
  • 1
  • 8
  • 26
  • 1
    From this question: https://stackoverflow.com/questions/20130768/retrieve-xy-data-from-matplotlib-figure Use `ax.lines[0].get_xdata()` and `ay.lines[0].get_xdata()` – Johannes Feb 24 '21 at 08:34
  • 1
    As mentioned in the comments, it gets the value of the graph object. `fig_child = fig2.get_children();fig_child[1].lines[0].get_ydata()` – r-beginners Feb 24 '21 at 09:26
  • Worked great! Thanks all! – Travasaurus Feb 24 '21 at 20:58

0 Answers0