Home > front end >  Matplotlib date time x axes custom date from file
Matplotlib date time x axes custom date from file

Time:06-11

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. Subplots

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

CodePudding user response:

This should do the job-

from datetime import datetime


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