use pandas csv reader and use subplots

This commit is contained in:
interfisch 2024-07-16 23:51:28 +02:00
parent a68df6afab
commit 890daa9702
2 changed files with 40 additions and 47 deletions

View File

@ -1,52 +1,47 @@
import matplotlib.pyplot as plt
import csv
#import csv
import pandas as pd
x=[]
speed_FrontL=[]
speed_FrontR=[]
speed_RearL=[]
speed_RearR=[]
fp = open('LOG00203c_replacedFrontLeftWheel.TXT')
rdr = csv.DictReader(filter(lambda row: row[0]!='#', fp))
for row in rdr:
#print(row)
x.append(float(row['cmd_FrontL']))
speed_FrontL.append(float(row['speed_FrontL']))
speed_FrontR.append(float(row['speed_FrontR']))
speed_RearL.append(float(row['speed_RearL']))
speed_RearR.append(float(row['speed_RearR']))
fp.close()
import numpy as np
#plt.plot(x,y, label='Loaded from file!')
scattersize=5
import argparse
parser = argparse.ArgumentParser(description='Analyzes fixed csv logs from bobbycar')
parser.add_argument('-i', '--input', type=argparse.FileType('r'), required=True, help="input csv log file")
args = parser.parse_args()
df = pd.read_csv(args.input.name)
x = df['timestamp']
x = [i-x[0] for i in x] #offset time by starttime
scattersize=1
scatteralpha=0.1
plt.scatter(x,speed_FrontL, s=scattersize, alpha=scatteralpha, label="speed_FrontL")
plt.scatter(x,speed_FrontR, s=scattersize, alpha=scatteralpha, label="speed_FrontR")
plt.scatter(x,speed_RearL, s=scattersize, alpha=scatteralpha, label="speed_RearL")
plt.scatter(x,speed_RearR, s=scattersize, alpha=scatteralpha, label="speed_RearR")
plt.xlabel('cmd')
plt.ylabel('speed')
plt.title('Interesting Graph\nCheck it out')
plt.legend()
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
#plt.scatter(x,df['rpm_FrontL'], s=scattersize, alpha=scatteralpha, label="rpm_FrontL")
ax1.plot(x,np.array(df['vbat_Front']), c='b', alpha=0.5, label="vbat_Front")
ax1.plot(x,np.array(df['vbat_Rear']), c='r', alpha=0.5, label="vbat_Rear")
ax2.plot(x,np.array(df['cmd_FrontL']), c='r', alpha=0.5, label="cmd_FrontL")
#plt.plot(x,np.array(df['currentConsumed']), c='g', alpha=0.5, label="currentConsumed")
#plt.scatter(x,df['rpm_FrontR'], s=scattersize, alpha=scatteralpha, label="rpm_FrontR")
ax1.set_xlabel('timestamp')
#plt.ylabel('data')
ax1.set_ylabel('first axis')
ax2.set_ylabel('second axis')
#plt.title('')
ax1.legend(loc='upper left')
ax2.legend(loc='upper right')
plt.show()
'''
with open(,'r') as csvfile:
plots = csv.reader(filter(lambda row: row[0]!='#', csvfile), delimiter=',')
for row in plots:
x.append(float(row[0]))
y.append(float(row[1]))
plt.plot(x,y, label='Loaded from file!')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Interesting Graph\nCheck it out')
plt.legend()
plt.show()
'''
exit()

View File

@ -107,8 +107,6 @@ if (args.consecutive):
print("")
print(inputFilenames)
else:
@ -150,7 +148,7 @@ for inputFilename in inputFilenames:
linesStarttime+=_linesStarttime
print("Line in file="+str(len(inputlines)))
print("Lines in file="+str(len(inputlines)))
assert len(lines)==len(linesStarttime), "Length of lines and linesStarttime does not match"