Search code examples
pythonnumpymatplotlibgenfromtxt

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()

but this code shows this error message :

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.

Solution

  • Try your path with / rather than \. That's how you specify the path. In a string \ acts as an escape character. You can also use \\