的我正在使用此代碼:NumPy的指數超出範圍錯誤
r = mlab.csv2rec(datafile, delimiter=';')
fig = plt.figure()
fig.subplots_adjust(bottom=0.2)
ax = fig.add_subplot(111)
ax.plot(r.date, r.close)
但它返回這樣的:
ax.plot(r.date, r.close)
IndexError: index out of range for array
如何確保我真的住在陣列範圍之內?
如果打印出LEN(r.date)和len(r.close)它們都返回:500
EDIT,這是從一個matplotlib示例代碼,使用NPY文件,我倒是想爲電子CSV文件做同樣的:
datafile = cbook.get_sample_data('goog.npy')
r = np.load(datafile).view(np.recarray)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(r.date, r.adj_close)
編輯,完整的錯誤日誌:
Traceback (most recent call last):
File "main02.py", line 66, in <module>
ax.plot(r['date'], r['close'])
File "/usr/lib/python2.6/site-packages/matplotlib/axes.py", line 3788, in plot
self.autoscale_view(scalex=scalex, scaley=scaley)
File "/usr/lib/python2.6/site-packages/matplotlib/axes.py", line 1824, in autoscale_view
y0, y1 = ylocator.view_limits(y0, y1)
File "/usr/lib/python2.6/site-packages/matplotlib/ticker.py", line 1170, in view_limits
return np.take(self.bin_boundaries(dmin, dmax), [0,-1])
File "/film/tools/PythonExtensions/v41/py26_linux-x64/numpy/core/fromnumeric.py", line 103, in take
return take(indices, axis, out, mode)
IndexError: index out of range for array
嗯。我剛剛生成了一個包含500行的測試csv數據文件,標記爲date和close的列以及分號分隔符,上述內容適用於我。 – DSM 2011-06-09 06:39:22
嗯,它會與這個文件? http://db.tt/MIOqFA0 – 2011-06-09 06:48:28