Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
810 views
in Technique[技术] by (71.8m points)

python - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...