How to convert datetime index of matplotlib to month

Viewed 244

I have made this graph in matplotlib notebook magic. I want to convert the datetimes into months as they seem messy like this. What to do?

enter image description here

1 Answers

The easiest way would probably be using the datetime module:

import datetime
x_values = [d.strftime("%b %y") for d in dates]
plt.plot(x_values, y_values)

Which outputs Jan 15 instead of 2015-01. If you want to plot the full year and month name, you can use "%B %Y".

Related