Skip to content

Instantly share code, notes, and snippets.

@theterg
Created November 13, 2013 14:07
Show Gist options
  • Select an option

  • Save theterg/7449680 to your computer and use it in GitHub Desktop.

Select an option

Save theterg/7449680 to your computer and use it in GitHub Desktop.
Matplotlib live plot animation without blitting
import pylab as plt
import numpy as np
import pandas as pd
import random
import time
start = time.time()
frames = pd.DataFrame([0], [0.0], ['data'])
plt.ion()
graph = plt.plot(frames.index, frames.data)[0]
diffs = []
while True:
newframe = pd.DataFrame([random.random()], [time.time()-start], ['data'])
frames = frames.append(newframe)
print len(frames)
graph.set_ydata(frames.data)
graph.set_xdata(frames.index)
plt.xlim(0, frames.index[-1])
plt.ylim(min(frames.data), max(frames.data))
plt.draw()
if len(frames) > 0 and len(frames) % 250 == 0:
thing = np.array(frames.index)
thing = 1.0/np.diff(thing)
diffs.append(thing)
if len(frames) > 2000:
break
plt.figure()
plt.ioff()
plt.hold(True)
for thing in diffs:
plt.hist(thing, bins=40, alpha=0.6)
legend = []
idx = 0
for thing in diffs:
legend.append("rate"+str(idx))
idx += 1
plt.legend(legend)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment