Last active
May 16, 2016 13:13
-
-
Save danijar/3524746066ab4ef037c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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