Created
March 18, 2016 08:42
-
-
Save BastinRobin/9b62237e34ff0ce01a4e to your computer and use it in GitHub Desktop.
Python Realtime Graph
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
| """ sampleText.txt | |
| 1,2 | |
| 2,3 | |
| 3,6 | |
| 4,9 | |
| 5,4 | |
| 6,7 | |
| 7,7 | |
| 8,4 | |
| 9,3 | |
| 10,7 | |
| """ | |
| import matplotlib.pyplot as plt | |
| import matplotlib.animation as animation | |
| import time | |
| fig = plt.figure() | |
| ax1 = fig.add_subplot(1,1,1) | |
| def animate(i): | |
| pullData = open("sampleText.txt","r").read() | |
| dataArray = pullData.split('\n') | |
| xar = [] | |
| yar = [] | |
| for eachLine in dataArray: | |
| if len(eachLine)>1: | |
| x,y = eachLine.split(',') | |
| xar.append(int(x)) | |
| yar.append(int(y)) | |
| ax1.clear() | |
| ax1.plot(xar,yar) | |
| ani = animation.FuncAnimation(fig, animate, interval=1000) | |
| plt.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment