Matplotlib 中的 X 轴打印随机数而不是年份 [英] X axis in Matplotlib print random numbers instead of the years
问题描述
我是这只Pandas和Matplotlib的新手,我从书中举了一个例子,显然它给了我警告
Im new in this Pandas and Matplotlib, I follow an example from a book and apparently it give me a warning
"MatplotlibDeprecation警告:epoch2num 函数在 Matplotlib 3.3 中已弃用,并将在两个次要版本后删除.base = date.epoch2num(dt.asi8/1.0e9)"
"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)"
并且轴的X值从年份变化为一些随机数
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()
推荐答案
这是由于Matplotlib和Pandas之间的暂时性不良互动引起的,并且在两个项目中均已解决.
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'
这篇关于Matplotlib 中的 X 轴打印随机数而不是年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!