[Python] Uneven intervals between x-axis with datetime

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

  1. Stack

    Stack Membro Participativo

    I am currently experiencing an issue where the spaces between ticks on my plot appear to have uneven intervals when using a DatetimeIndex for my x-axis. The code is as follows:

    x = pd.date_range('2018-11-03', '2018-12-30')
    plt.plot(x, np.arange(len(x)))
    plt.xticks(rotation=45)


    [​IMG]

    Note the two instances in which the dates do not increment by the typical 7-day period. Even after extending the time period, the issue persists:

    x = pd.date_range('2018-11-03', '2019-03-20')
    plt.plot(x, np.arange(len(x)))
    plt.xticks(rotation=45)


    [​IMG]

    How can I override this behavior to have standard 7-day intervals on my plot? Thank you.

    Continue reading...

Compartilhe esta Página