X axis in Matplotlib print random numbers instead of the years

前端 未结 3 1761
广开言路
广开言路 2020-12-07 01:54

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 w

相关标签:
3条回答
  • 2020-12-07 02:09

    import matplotlib.pyplot as plt
    from pandas_datareader import data
    
    
    AMZ = data.DataReader('AMZN', start='2011', end='2018', data_source='yahoo')
    
    AMZ = AMZ['Close']
    
    fig, ax = plt.subplots(figsize=(16, 9))
    
    plt.plot(AMZ.index, AMZ, label='AMZ')
    plt.plot(AMZ.resample('BA').mean().index, AMZ.resample('BA').mean(), label='resample', linestyle=':')
    plt.plot(AMZ.asfreq('BA').index, AMZ.asfreq('BA'), label='asfreq', linestyle='--')
    
    ax.set_xlabel('Date')
    
    plt.show()
    

    This should work like a charm

    0 讨论(0)
  • 2020-12-07 02:24

    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'
    
    0 讨论(0)
  • 2020-12-07 02:26

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

    0 讨论(0)
提交回复
热议问题