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

前端 未结 3 828
南笙
南笙 2020-12-16 19:11

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_ma

3条回答
  •  醉梦人生
    2020-12-16 19:45

    You could just pass new labels exactly with your preferred strftime:

    ax.set_xticklabels([pandas_datetime.strftime("%Y-%m-%d") for pandas_datetime in df.index])
    

    It's not the prettiest answer, but it gets the job done consistently.

提交回复
热议问题