views:

710

answers:

2

I have an array of timestamps in the format (HH:MM:SS.mmmmmm) and another array of floating point numbers, each corresponding to a value in the timestamp array.

Can I plot time on the x axis and the numbers on the y-axis using matplotlib? I was trying to but somehow it was only accepting arrays of floats.How can I get it to plot the time? Do i have to modify the format in anyway?

+1  A: 

You must first convert your timestamps to python datetime objects (use datetime.strptime). Then use date2num to convert the dates to matplotlib format.

Plot the dates and values using plot_dates:

dates = matplotlib.dates.date2num(list_of_datetimes)
plot_dates(dates, values)
codeape
will it plot the Date or just the time? I only want the time since on conversion to datetime, the year is set to 1990.
TP
"... on conversion to datetime, the year is set to 1990": Could you please post the code you use to convert from string to datetime? Something might be wrong with the conversion. Re. the formatting of chart labels, see the date_demo1 link provided by J. K. Seppänen. The matplot lib documentation is excellent, BTW. http://matplotlib.sourceforge.net/index.html
codeape
+1  A: 

Look at some examples:

To make it only show times and not dates, pass a suitable strftime-like spec to DateFormatter.

Jouni K. Seppänen