I’m using matplotlib to plot data as a function of time in hh:mm:ss.ms format where ms is milliseconds. However, I don’t see the milliseconds in the plot. Is it possible to add them as well?
dates = matplotlib.dates.datestr2num(x_values) # convert string dates to numbers
plt.plot_date(dates, y_values) # doesn't show milliseconds
The problem here is that there is a class to format ticks, and plot_date sets that class to something that you don’t want: an automatic formatter that never plots milliseconds.
In order to change this, you need to change from
matplotlib.dates.AutoDateFormatterto your own formatter.matplotlib.dates.DateFormatter(fmt)creates a formatter with adatetime.strftimeformat string. I’m not sure how to get this to show milliseconds, but it will show microseconds, which I hope will work for you; it’s just one extra zero, after all. Try this code: