It seems you need the matplotlib.animation function. animation examples .
EDIT: Added a simple code example of my version.
import random
from matplotlib import pyplot as plt
from matplotlib import animation
def data_generator(t):
if t<100:
return random.sample(range(100), 20)
def init():
return plt.plot()
def animate(i):
data = data_generator(i)
return plt.plot(data, c='k')
fig = plt.figure()
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=1000, interval=1000, blit=True)
plt.show()
EDIT2: multi-line version in real time.
import random
from matplotlib import pyplot as plt
from matplotlib import animation
def data_generator_1(t):
if t<100:
x1.append(t)
y1.append(random.randint(1, 100))
def data_generator_2(t):
if t<100:
x2.append(t)
y2.append(random.randint(1, 100))
def init():
global x1
global y1
x1 = []
y1 = []
global x2
global y2
x2 = []
y2 = []
l1, l2 = plt.plot(x1, y1, x2, y2)
return l1, l2
def animate(i):
data_generator_1(i)
data_generator_2(i)
l1, l2 = plt.plot(x1, y1, x2, y2)
plt.setp(l1, ls='--', c='k')
plt.setp(l2, c='gray')
return l1, l2
fig = plt.figure()
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=1000, interval=1000, blit=True)
plt.show()

, . , , .
ipython/vanilla, . ( ipython). , matplotlib.