I have a .csv file with only two columns in it, date and time:
04-02-15,11:15
04-03-15,09:35
04-04-15,09:10
04-05-15,18:05
04-06-15,10:30
04-07-15,09:20
I need this data to be plotted (preferably in an area graph, haven't gotten that far yet) using matplotlib. I need the y-axis to be time, and the x-axis to be date. I'm having trouble wrapping my head around some of the usage for time/date, and was hoping someone could take a look at my code and offer some guidance:
import numpy as np
from pylab import *
import matplotlib.pyplot as plt
import datetime as DT
data= np.loadtxt('daily_count.csv', delimiter=',',
dtype={'names': ('date', 'time'),'formats': ('S10', 'S10')} )
x = [DT.datetime.strptime(key,"%m-%d-%y") for (key, value) in data ]
y = [DT.datetime.strptime(key,"%h:%m") for (key, value) in data]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.grid()
fig.autofmt_xdate()
fig.autofmt_ytime()
plt.plot(x,y)
plt.xlabel('Date')
plt.ylabel('Time')
plt.title('Peak Time')
plt.show()
Each time I try to run it, I get this error:
ValueError: time data '04-02-15' does not match format '%h:%m'
I've also got a suspicion about the ticks for the y-axis, which thus far don't seem to be established. I'm very open to suggestions for the rest of this code as well - thanks in advance, internet heroes!