用python绘制每日概要文件
我想做一个每日剖面图:小时与浓度。我正在使用matplotlib和datetime模块 当我写作时:用python绘制每日概要文件,python,datetime,time,matplotlib,plot,Python,Datetime,Time,Matplotlib,Plot,我想做一个每日剖面图:小时与浓度。我正在使用matplotlib和datetime模块 当我写作时: import datetime from pylab import * b = [datetime.time(12,0), datetime.time(13,0)] c = [4,5] plot(b,c) show() 。。。它不起作用 我必须使用datetime对象而不是time对象才能进行绘图: a = [datetime.datetime(2005,5,10,12), datetime.
import datetime
from pylab import *
b = [datetime.time(12,0), datetime.time(13,0)]
c = [4,5]
plot(b,c)
show()
。。。它不起作用
我必须使用datetime对象而不是time对象才能进行绘图:
a = [datetime.datetime(2005,5,10,12), datetime.datetime(2005,5,10,13)]
c = [4,5]
plot(a,c)
show()
但我真的希望能够使用时间对象而不是datetime来绘制绘图。。。
有什么想法吗?时间返回秒数
>>>print time.time()
1297696979.78
>>>print date.fromtimestamp(today)
2011-02-14
今天作为一个变量,我将其设置为当前时间。time()。我不太清楚为什么要在time()函数中输入变量 在此处查看matplotlib文档: 问题是matplotlib只知道如何将datetime对象转换为浮点,并且看起来对datetime.time没有相同的支持 编辑: 一种可能的解决方案是只获取一个默认日期(“今天”),然后将其与您想要的特定时间相结合(如果您不关心日期):
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()
谢谢你的回答。我使用的是datetime.time类(datetime模块),它具有hour、minute、second、microsecond和tzinfo属性。我只输入小时和分钟值。我会这样做。谢谢乔希的帮助。