加载数据文件进行绘图时出现 IOError

IOError when loading data file to plot

import matplotlib.pyplot as plt

import numpy as np

x,y = np.genfromtxt('D:\Tanjil\Python\directory\Heat Available Datas.csv',unpack=True , delimiter=',',skip_header=0)

plt.plot(x,y,'ro--'),

plt.ylabel('Power Input (kW)'),

plt.xlabel('Speed(rpm)'),

plt.show()

但是此代码显示此错误消息:

File "C:\Users\bad_tanjil\Anaconda\lib\site-packages\numpy\lib\_datasource.py", line 151, in open
    return ds.open(path, mode)

  File "C:\Users\bad_tanjil\Anaconda\lib\site-packages\numpy\lib\_datasource.py", line 501, in open
    raise IOError("%s not found." % path)

IOError: D:\Tanjil\Python\directory\Heat Available Datas.csv not found.

尝试使用 / 而不是 \。这就是您指定路径的方式。在字符串中 \ 充当转义字符。您也可以使用 \

改变

'D:\Tanjil\Python\directory\Heat Available Datas.csv'

'D:\Tanjil\Python\directory\Heat Available Datas.csv'

或者

(r'D:\Tanjil\Python\directory\Heat Available Datas.csv')