Matplotlib date time x axes custom date from file


Let me explain!

I’m working with the subplots shown in image 1 with python and matplotlib. I have my data stored in csv, and the date comes in the format shown in the picture. I want the date shown in the xaxis to be in the format month/day only: from 2022-04-04 11:00 to 04-04.

I’ve tried this but i can’t customize my date:

x = [dt.datetime.strptime(d, ‘%Y-%m-%d %H:%M’).date() for d in date


This should do the job-

from datetime import datetime

x = list()
for d in date:
    dt = datetime.strptime(d, "%Y-%m-%d %H:%M")

Answered By – mrVerma

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published