我有Python 2.7 Win 32,并安装了Matplotlib, Numpy, PyParsing, Dateutil。在IDLE中,我放入以下代码:
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import matplotlib.dates as mdates
import numpy as np
ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)
def graphRawFX () :
global ax1
date=mdates.strpdate2num('%Y%m%d%H%M%S')
bid, ask = np.loadtxt('GPBUSD1d.txt', unpack=True)
delimiter=',',
converters={0:mdates.strpdate2num('%Y%m%d%H%M%S') }
fig = plt.figure(figsize=(10,7))
ax1.plot(date,bid)
ax1.plot(date,ask)
graphRawFX()
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
plt.grid(True)
plt.show()
我继续运行代码,出现以下错误:
>>>
Traceback (most recent call last):
File "C:/Users/Emanuel/Desktop/graphing.py", line 22, in <module>
graphRawFX()
File "C:/Users/Emanuel/Desktop/graphing.py", line 14, in graphRawFX
bid, ask = np.loadtxt('GPBUSD1d.txt', unpack=True)
File "C:Python27libsite-packagesnumpylibnpyio.py", line 734, in loadtxt
fh = iter(open(fname, 'U'))
IOError: [Errno 2] No such file or directory: 'GPBUSD1d.txt'
>>>
非常奇怪,因为我在桌面上有gpbusd1 .txt文件。它曾经是在一个。zip文件夹中,但我把它拿出来,因为我知道如果压缩,python找不到它。
尝试将绝对路径添加到GPBUSD1d.txt文件中。它可能试图从python运行的目录中查找文件。