繁体   English   中英

沿x轴绘制日期时间

[英]plotting datetime along the x-Axis

嗨,我正在尝试在x轴上绘制日期时间数组。 但是我似乎在实际绘制它们时遇到了问题,并不断出现值错误:

ValueError: invalid literal for long() with base 10: '2013-02-18 00:00:00'

有谁知道我要去哪里错了?

数据本身格式化为四列,并且在打印时如下所示:('04 / 03/2013',7.0,12.0,17.0)('11 / 03/2013',23.0,15.0,23.0)。

import csv
import numpy as np
import pylab as pl
import datetime
from datetime import datetime
data = np.genfromtxt('H:/AppliedGIS/Python/AssignmentData/GrowthDistribution/full.csv', names=True, usecols=(0, 1, 2, 3), delimiter= ',', skiprows=1, dtype =[('Date', 'S10'),('HIGH', '<f8'), ('Medium', '<f8'), ('Low', '<f8')])
print data
x =  [foo[0] for foo in data]
y =  [foo[1] for foo in data]
y2 = [foo[2] for foo in data]
y3 = [foo[3] for foo in data]
print x, y, y2, y3
dates = []
for i in x:
    date = datetime.datetime.strptime['i', '%d/%m/%Y']
    dates.append(date)

pl.plot(data[:, dates], data[:, y], '-r', label= 'High Stocking Rate')
pl.plot(data[:, dates], data[:, y2], '-g', label= 'Medium Stocking Rate')
pl.plot(data[:, dates], data[:, y3], '-b', label= 'Low Stocking Rate')
pl.title('Amount of Livestock Grazing per hectare', fontsize=18)
pl.ylabel('Livestock per ha')
pl.xlabel('Date')
pl.grid(True)
pl.ylim(0,100)
pl.show()

我立即在代码中看到两个问题。

date = datetime.datetime.strptime['i', '%d/%m/%Y'] should be
date = datetime.datetime.strptime('i', '%d/%m/%Y')

pl.plot(data[:, dates], data[:, y], '-r', label= 'High Stocking Rate')

Try this instead:
pl.plot_date(dates, y, '-r', label= 'High Stocking Rate')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM