#!/usr/bin/env python
from sys import argv, stdin
from pylab import plot, xlabel, ylabel, legend, show, savefig
from scipy import polyfit, polyval

# Collect data
x = []
y = []
for line in stdin.readlines():
    s, t = map(float, line.split(',', 1))
    x.append(s)
    y.append(t)

# Least squares data fit
c = tuple(polyfit(x, y, 1).tolist())
fit = polyval(c, [0, x[-1]])

# Plot and optionally save data
plot(x, y, 'x', label='metingen')
plot([0, x[-1]], fit, '-', label='Least Squares fit (y = %ex + %e)' % c)
legend()
xlabel('Pakketgrootte')
ylabel('Tijd (s)')
if len(argv) == 2:
    savefig(argv[1])
show()
