包我有一組數據在這樣一個文本文件:Python的繪製時間與基於CSV文件
99150, 2012-05-18 14:30:08.592276
100350, 2012-05-18 14:31:09.093357
97710, 2012-05-18 14:32:09.583485
94980, 2012-05-18 14:33:10.047794
95670, 2012-05-18 14:34:10.559798
97170, 2012-05-18 14:35:11.073576
98850, 2012-05-18 14:36:11.562930
98280, 2012-05-18 14:37:12.058591
97950, 2012-05-18 14:38:12.547585
102510, 2012-05-18 14:39:13.053431
我想讓它的一個簡單的情節和輸出的圖像。我已經開始與以下:
#!/bin/python
import csv
import matplotlib.pyplot as plt
import numpy as np
filename="pps_counter.log"
def getColumn(filename, column):
results = csv.reader(open(filename), delimiter=",")
return [result[column] for result in results]
time = getColumn(filename,1)
packets = getColumn(filename,0)
plt.figure("Packets Per Minute")
plt.xlabel("Time(minutes)")
plt.ylabel("Number of Packets")
plt.plot(time,packets)
當我運行此我得到以下錯誤:
Traceback (most recent call last):
File "plotter.py", line 16, in <module>
time = getColumn(filename,1)
File "plotter.py", line 14, in getColumn
return [result[column] for result in results]
IndexError: list index out of range
誰能幫助?
太棒了!謝謝,我已經定製了圖形並將其設置爲輸出到文件中......謝謝。 – secumind