Skip to content

Instantly share code, notes, and snippets.

@Hamster-Furtif
Last active May 30, 2017 18:42
Show Gist options
  • Save Hamster-Furtif/2c52e08a35526352cea0b1906faa6e23 to your computer and use it in GitHub Desktop.
Save Hamster-Furtif/2c52e08a35526352cea0b1906faa6e23 to your computer and use it in GitHub Desktop.
A parser for any .csv file
import matplotlib.pyplot as plt
def openFile(name, maxTime=0):
file = open(name+".txt")
tab = file.read()
tab=tab.split("\n")
names=tab[0].split("\t")
if(maxTime==0):
maxTime=len(tab)
new_tab = []
for i in range(len(names)):
new_tab.append([])
for i in range(1,maxTime-1):
split=tab[i].split("\t")
for j in range(0,len(split)):
new_tab[j].append(float(split[j]))
print(maxTime)
print(names)
return names,new_tab
def showGraph(x,ys,names,ls):
l1=[]
l2=[]
for y in ys:
p,=plt.plot(ls[x],ls[y], label=names[y])
l1.append(p)
l2.append(names[y])
plt.legend(l1,l2)
plt.xlabel(names[x])
plt.show()
def castToFloat(string):
string=string.replace(',','.')
if'E' in string:
return float(string[:-3])*pow(10,float(string[-2:]))
else:
return float(string)
# a,b=openFile("mbcrea-10kg")
# showGraph(0,[1,2],a,b)
def showAllData(name, maxT=0):
a,b=openFile(name, maxTime=maxT)
ys=[]
for i in range(1,len(a)):
ys.append(i)
showGraph(0,ys,a,b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment