Skip to content

Instantly share code, notes, and snippets.

@danijar
Last active May 16, 2016 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danijar/3524746066ab4ef037c2 to your computer and use it in GitHub Desktop.
Save danijar/3524746066ab4ef037c2 to your computer and use it in GitHub Desktop.
import random
import time
import threading
import matplotlib.pyplot as plt
class Plot:
def __init__(self):
plt.ion()
plt.show()
self.xdata = []
self.ydata = []
self.running = None
self.axis = plt.figure().add_subplot(111)
self.line, = self.axis.plot([])
def start(self):
self.running = True
threading.Thread(target=self.worker).start()
while self.running:
self.axis.set_xlim(0, len(self.xdata))
self.axis.set_ylim(0, max(self.ydata))
self.line.set_data(self.xdata, self.ydata)
plt.draw()
plt.pause(0.001)
time.sleep(1)
def worker(self):
for _ in range(100):
self.xdata.append(len(self.xdata))
self.ydata.append(random.random())
time.sleep(0.1)
self.running = False
if __name__ == '__main__':
start = time.time()
Plot().start()
print(time.time() - start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment