The link provided by Paul H ( http://matplotlib.org/examples/api/date_demo.html ) uses the following line of code to set the format:
ax.format_xdata = mdates.DateFormatter('%Y-%m-%d')
This does not work with my python 3 installation, which is the original installation that comes with jupyter. Instead, you need to install it using the Paul viz-a-viz line of code:
ax.xaxis.set_major_formatter(myFmt)
Oddly enough, this is not enough on the matplotlib website, so watch out for this error. Here is the complete code I used:
## Rotate date labels automatically import matplotlib.pyplot as plt from matplotlib.dates import DateFormatter fig, ax = plt.subplots() ax.plot(myDates,myValues) fig.autofmt_xdate() myFmt = DateFormatter("%d") ax.xaxis.set_major_formatter(myFmt) plt.show()
Robino Apr 26 '17 at 10:04 on 2017-04-26 10:04
source share