I'm trying to implement an application that plots data in a real time fashion. I have tried some code I found in this question but it doesn't work. The figure plots one result before the for
loop and one result when the for
loop is done
This is run in Ubuntu, from the Python interpreter.
The code I'm referring to:
import numpy as np
import matplotlib.pyplot as plt
plt.ion()
mu, sigma = 100, 15
fig = plt.figure()
x = mu + sigma*np.random.randn(10000)
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='green', alpha=0.75)
for i in range(50):
x = mu + sigma*np.random.randn(10000)
n, bins = np.histogram(x, bins, normed=True)
for rect,h in zip(patches,n):
rect.set_height(h)
fig.canvas.draw()