- 积分
- 6313
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2013-1-15
- 最后登录
- 1970-1-1
|
发表于 2016-10-21 14:29:12
|
显示全部楼层
王老师,您好!开始也考虑过这个问题,但是加上bar(times, b, color='b'),脚本运行就会出错了,而且右边的y轴范围发生变化,ylim(0,60)以及ylabel('rain', color='k')不起任何作用,这是怎么回事呢?如下图:
#Read lighting data
fn = 'f:/shandianshujuchuli/79.txt'
tf = open(fn)
times = []
nums = []
for h in range(0, 24):
times.append(datetime.datetime(2016,7,9,h))
nums.append(0)
for aline in tf:
datalist = aline.split()
h = int(datalist[2].split(':')[0])
nums[h] = nums[h] + 1
#Plot
ax1 = axes()
xaxis(ax1, color='k')
yaxis(ax1, color='k')
plot(times, nums, '-ro')
xlim(times[0], times[-1])
xaxis(axistype='time')
ylabel('Lighting number')
title('Lighting number hourly variation in ' + times[0].strftime('%Y/%m/%d'))
#bar
ax2 = twinx(ax1)
yaxis(ax2, color='k')
b=[10,15,18,20,50,8,8,20,50,8,20,50,8,8,20,10,15,18,20,50,8,9]
#bar(b,0.3,color='b')
bar(times,b,0.3,color='b')
ylim(0,60)
#xlim(times[0], times[-1])
ylabel('rain', color='k')
|
|