Skip to content

Instantly share code, notes, and snippets.

@hirokai
Created October 21, 2015 00:09
Show Gist options
  • Save hirokai/eaacf9ae6e4681eeada6 to your computer and use it in GitHub Desktop.
Save hirokai/eaacf9ae6e4681eeada6 to your computer and use it in GitHub Desktop.
Collect minimum values in csv
#!/usr/bin/env python
import matplotlib.pyplot as plt
import glob
import csv
y_mins = []
file_list = glob.glob('*.csv')
print('Reading %d files...\n' % len(file_list))
times = []
for i, path in enumerate(file_list):
plt.subplot(8, 6, i + 1)
with open(path, 'rU') as f:
reader = csv.reader(f, delimiter=',')
for _ in range(6):
reader.next()
row = reader.next()
times.append(row[0].split(' ')[-1])
for _ in range(6):
reader.next()
vs = []
for row in reader:
try:
vs.append(map(float, row))
except ValueError:
pass
xs = map(lambda a: a[1], vs)
ys = map(lambda a: a[0], vs)
plt.plot(xs, ys, '-b')
y_mins.append(min(ys))
print('|min(force)| [mN] (= adhesion force)')
print('=====')
for p, v in zip(file_list, y_mins):
print('%s\t%d' % (p, int(-v * 1000)))
print('=====')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment