plot a daily profile with python
I want to make a daily profile plot: hour vs concentrations. I开发者_JS百科'm using matplotlib and datetime module.
When I write:
import datetime
from pylab import *
b = [datetime.time(12,0), datetime.time(13,0)]
c = [4,5]
plot(b,c)
show()
... it doesn't work.
I have to use datetime objects instead of time objects to be able to make the plot:
a = [datetime.datetime(2005,5,10,12), datetime.datetime(2005,5,10,13)]
c = [4,5]
plot(a,c)
show()
But I really would like to be able to make the plot using time objects instead of datetime... Any ideas?
Have a look at the matplotlib documentation here:
http://matplotlib.sourceforge.net/api/dates_api.html
The issue is that matplotlib only knows how to convert the datetime object to a float and it doesn't look there is the same support for datetime.time
Edit: One possible solution is to just get a default date ('today') and then combine it with the specific time you want if you don't care about the date:
import datetime
from pylab import *
d = datetime.date.today()
tt = [datetime.time(12,0), datetime.time(13,0)]
b = []
for t in tt:
b.append(datetime.datetime.combine(d,t))
c = [4,5]
plot(b,c)
show()
Time returns the amount of seconds.
>>>print time.time()
1297696979.78
>>>print date.fromtimestamp(today)
2011-02-14
Today being a variable I set equal to the current time.time(). I'm not quite sure why you're entering variables into the time() function.
精彩评论