#!/usr/bin/env python
from sys import stdin, argv, exit
from pylab import figure, plot, axis, draw, ion, clf
from time import sleep

if len(argv) < 2:
    print 'Usage: python %s TIME_STEP [ DELAY ]' % argv[0]
    exit()

stride = int(argv[1])
delay = .1 if len(argv) < 3 else float(argv[2])

# Collect data
lines = stdin.readlines()
y = []
x = map(float, lines[0].split(' '))
for line in lines[1::stride]:
    y += [map(float, line.split(' '))]

# Find axis maxima
max_y = max([max(map(abs, y[i])) for i in range(len(y))])
ranges = [0, max(x), -max_y, max_y]

# Plot data in animation
ion()
figure(1)
for i in range(len(y)):
    clf()
    plot(x, y[i], '-')
    axis(ranges)
    draw()
    i and sleep(delay)
