-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Description
The default format to display time series xtick labels in time series plots seems to have been changed between matplotlib 1.4 and 1.5. When using time stamps in a datetime format with a 1 second resolution and plotting a minute worth of data, the major xtick labels are now formatted as "HH:MM:SS.mmmmm" as opposed to "HH:MM:SS" in matplotlib 1.4. This new behaviour doesn't match the significany of the timestamps and results in overlapping xtick labels as well.
A simple example to illustrate the issue:
import numpy as np
import matplotlib.pyplot as plt
import datetime
# generating time stamps with a resolution of 1s
x = np.array([datetime.datetime(2016, 5, 4, 12, 0, i) for i in range(60)])
# generating some random y-values
y = np.random.randn(x.shape[0]).cumsum()
# plot
plt.plot(x, y)
plt.show()
This results in the following figure:

Of course, the xtick label format can be manually adjusted:
import matplotlib.dates as dates
# create plot
plt.plot(x, y)
# get reference to x-axis
xax = plt.gca().get_xaxis()
# format major xtick label
xax.set_major_formatter(dates.DateFormatter('%H:%M:%S'))
# show plot
plt.show()
But I found the old behavior more elegant.
I'm using matplotlib 1.5.1 on Python 3.5.1 32-bit as part of the Anaconda3 4.0.0 Windows x86 distrubtion. The OS is Windows 7 64 bit.