0

I want to change my axis x where the value are 2019-01, 2019-02.. To 01-01-2019, 01-02-2019... I find it's due to the pd.to_datetime US default. I try different thing but nothing change...

ax1.plot(pd.to_datetime(DB['Date'], dayfirst=True), θPf2plot, color = 'gray', label = "Capacité au champ") 
ax1.plot(pd.to_datetime(DB['Date'], format='%d/%m/%Y'), θPf2plot, color = 'gray', label = "Capacité au champ") 

If you have any ideas, thank you for your help :) !

1 Answers1

1

pd.to_datetime just converts a string to datetimes. But it does not change the format.

To change the format in matplotlib you have to use DateFormatter as explained in this SO post.

It is hard to tell from your code snippet, but the solution should look like this:

import matplotlib.dates as mdates

ax1.set_xticks(pd.to_datetime(DB['Date'])
ax1.xaxis.set_major_formatter(mdates.DateFormatter("%d/%m/%Y"))
ax1.xaxis.set_minor_formatter(mdates.DateFormatter("%d/%m/%Y"))
above_c_level
  • 3,579
  • 3
  • 22
  • 37