[Python] Formatting datetime xlabels in matplotlib (pandas df.plot() method)

Discussão em 'Python' iniciado por Stack, Março 14, 2025.

  1. Stack

    Stack Membro Participativo

    I can't figure out how to change the format of these x-labels. Ideally, I'd like to call strftime('%Y-%m-%d') on them. I've tried things like set_major_formatter but was unsuccessful.

    import pandas as pd
    import numpy as np
    date_range = pd.date_range('2014-01-01', '2015-01-01', freq='MS')
    df = pd.DataFrame({'foo': np.random.randint(0, 10, len(date_range))}, index=date_range)
    ax = df.plot(kind='bar')


    [​IMG]

    Continue reading...

Compartilhe esta Página