I have made a graph on stock data using fbprophet
module in python. my graph looks like this :
The code i m using is this:
model = Prophet()
model.fit(df)
future = model.make_future_dataframe(periods=365) # forecasting for 1 year from now.
forecast = model.predict(future)
''' Plotting the forecast '''
figure = model.plot(forecast)
plt.plot = figure
figure.savefig('forecasting for 1 year.svg')
From above code i have made that graph. then i extracted the data points from it using mpld3
module
import mpld3
# print(mpld3.fig_to_dict(figure))
print(mpld3.fig_to_dict(figure)['data'])
It gives me output like this:
{'data01': [[734094.0, 3.3773930153824794], [734095.0, 3.379438304627263], ........ 'data03': [[0.0, 0.0]]}
But the problem is from the above output the y
values i m getting is correct but not the x
values.. The actual x values are like this :
"x": [
"2010-11-18 00:00:00",
"2010-11-19 00:00:00",
"2010-11-22 00:00:00" ... ]
but i m getting x values like this : 734094.0 , 734095.0 ..
So how can i get the actual data (data points x and y values ) from graph ??
Is there any other way to do it ? I want to extract data points from graph then send those from a flask api to UI (angular 4)
Thanks in advance!
734094 / 365.25 = 2009.8398. That's a very suggestive number for a date that, from your example, I assume is 2010-11-18. It looks like your date information is expressed as a floating-point number, where the difference of 1.0 corresponds to one day: and, the reference date for the value 0.0 is January 1, 1 AD.
You could try to write a function that counts from 01-01-1, or maybe you could find one in a library. Alternately, you could look at the converted value for a date you know, and work from there.