I have to plot the values from a csv file into graph using python. I am using the follow code in python. CODE:
import numpy as np
import matplotlib.pyplot as plt
def graph():
cv,dv = np.loadtxt('/home/test/test_mat.csv',delimiter=',',unpack=True)
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1,axisbg='white')
plt.plot(x=cv,y=dv)
plt.title('Chemical Presence')
plt.ylabel('dv')
plt.xlabel('cv')
plt.show()
graph()
In the code, I am trying to load the csv file from the location it is present. The data file looks like the screenshot attached here data file. Here col 1 = CV (X axis) and row1 = DV ( Y axis).
CV\Line 1 2 3 4 5
-7.49952 7.6904296 7.64923087 7.81402579 7.59429923 7.73162833
-7.48388 7.56683341 7.51190177 7.38830558 7.67669669 7.38830558
-7.46824 7.03124992 7.38830558 7.49816886 7.51190177 7.66296378
-7.4526 7.53936759 7.66296378 7.71789542 7.62176505 7.6904296
-7.43696 7.49816886 7.73162833 7.45697013 7.71789542 7.38830558
-7.42132 7.01751701 7.20977775 7.48443595 7.58056632 7.81402579
-7.40568 7.58056632 7.71789542 7.70416251 7.49816886 7.58056632
But I am getting an error while executing the code.The following is the error:
ERROR: File "/home/kishore/.local/lib/python2.7/site-packages/numpy/lib/npyio.py", line 928, in loadtxt items = [conv(val) for (conv, val) in zip(converters, vals)]
File "/home/kishore/.local/lib/python2.7/site-packages/numpy/lib/npyio.py", line 659, in floatconv
return float(x)
ValueError: could not convert string to float: CV\Line
I am new to Python programming. can anyone please help me in knowing how to solve this issue.
