I can find plenty of examples of plot_date() and the like, but how can I plot a time series where the x-axis is strings as returned by datetime.time.isoformat()? I am using microsecond data, and that appears to be a serious restriction.
Asked
Active
Viewed 1,794 times
2 Answers
1
Although this is an old quesstion, I would still like to point to a more detailed answer.
Basically, matplotlib can deal on its own with datetime.datetime objects. You can just plug them in as data. To fix your formating, use:
xfmt = matplotlib.dates.DateFormatter('%H:%M:%S:%f')
ax.xaxis.set_major_formatter(xfmt)
ax.plot(datetimes, data)
Adjust the format to suite your needs. Formating directives description can be found on PythonLibrary under 8.1.7.
0
You can use the DATETICK command to add date strings to your x axis:
>> datetick('x', 'yyyy/mm/dd HH:MM:SS.FFF', 'keeplimits', 'keepticks')
You may need to adjust the date format for your purposes and the 'keeplimits' and 'keepticks' options may or may not apply to your application.

b3.
- 7,094
- 2
- 33
- 48