Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X axis in Matplotlib print random numbers instead of the years

Im new in this Pandas and Matplotlib, I follow an example from a book and apparently it give me a warning

"MatplotlibDeprecationWarning: The epoch2num function was deprecated in Matplotlib 3.3 and will be removed two minor releases later. base = dates.epoch2num(dt.asi8 / 1.0e9)"

and the X value of axis change from years to some random numbers

import matplotlib.pyplot as plt
from pandas_datareader import data

AMZ = data.DataReader('AMZN', start='2011', end='2018', data_source='yahoo')
AMZ = AMZ['Close']

AMZ.plot()
AMZ.resample('BA').mean().plot(style=':')
AMZ.asfreq('BA').plot(style='--')

plt.show()

enter image description here

like image 504
prayoga yoga Avatar asked Jul 24 '20 17:07

prayoga yoga


2 Answers

This was caused by a temporary bad interaction between Matplotlib and Pandas and is fixed in both projects.

To work around until the new versions are available:

plt.rcParams['date.epoch'] = '0000-12-31'
like image 141
Jody Klymak Avatar answered Oct 01 '22 19:10

Jody Klymak


I ran your code and the axis shows the correct years. The problem is not coming from the code you posted here.

graph

like image 29
Luke B Avatar answered Oct 01 '22 17:10

Luke B