So, here I'm trying to plot a graph using the coordinates that are provided in a file. I'm opening the file and setting the coordinates in an array to feed the array as in put to the graph.
Code:
import matplotlib
import matplotlib.pyplot as plt
x=[]
y=[]
readFile=open("coordinates.txt","r")
data = readFile.read().split("\n")
print(data)
for i in data:
val = i.split(",")
x.append(int(val[0]))
y.append(int(val[1]))
plt.plot(x,y)
plt.show()
Output:
['3,22', '5,16', '-2,8', '10,43', '4,0', '']
Traceback (most recent call last):
File "/home/nishantsikri/matplotlib from file.py", line 14, in <module>
x.append(int(val[0]))
ValueError: invalid literal for int() with base 10: ''