Plotting datetimeindex on x-axis with matplotlib creates wrong ticks in pandas 0.15 in contrast to 0.14

前端 未结 2 415
梦谈多话
梦谈多话 2020-12-29 10:14

I create a simple pandas dataframe with some random values and a DatetimeIndex like so:

import pandas as pd
from numpy.random import randint
import datetime          


        
2条回答
  •  囚心锁ツ
    2020-12-29 10:56

    With matplotlib 1.5.0 this 'just works':

    import pandas as pd
    from numpy.random import randint
    import datetime as dt
    import matplotlib.pyplot as plt
    
    # create a random dataframe with datetimeindex
    dateRange = pd.date_range('1/1/2011', '3/30/2011', freq='D')
    randomInts = randint(1, 50, len(dateRange))
    df = pd.DataFrame({'RandomValues' : randomInts}, index=dateRange)
    
    fig, ax = plt.subplots()
    ax.plot('RandomValues', data=df)
    

提交回复
热议问题