Home > Software design >  Format Seaborn x axis to MM/DD/YYYY Format
Format Seaborn x axis to MM/DD/YYYY Format

Time:03-04

I am wondering how to format my X axis : Currently my axis looks like as follow :

enter image description here

The dream would be to get :

enter image description here

Strugling with this, I tried to convert my Date array to other formats but still does not work.

Currently My array is :

DateList = np.array(list(MaVar['Dates'].tail(6)))

Print(DateList)
-------------
[Timestamp('2021-09-30 00:00:00') Timestamp('2021-10-31 00:00:00')
 Timestamp('2021-11-30 00:00:00') Timestamp('2021-12-31 00:00:00')
 Timestamp('2022-01-31 00:00:00') Timestamp('2022-02-28 00:00:00')]

The code where I set x axis is below :

sns.heatmap(MatrixData, xticklabels=DateList)

CodePudding user response:

Extract the dates from the Timestamps with dt.date:

DateList = np.array(list(MaVar['Dates'].dt.date.tail(6)))
  • Related