Skip to content

Instantly share code, notes, and snippets.

@adessein
Created May 16, 2019 20:43
Show Gist options
  • Save adessein/1c6106fbfe74e70cbd3e35f116116b32 to your computer and use it in GitHub Desktop.
Save adessein/1c6106fbfe74e70cbd3e35f116116b32 to your computer and use it in GitHub Desktop.
Matplotlib live graph
# Solution 1 - to be tested
# Source : # https://www.youtube.com/watch?v=ZmYPzESC5YY
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import stype
style.use('fivethirtyeight')
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
def animate(i):
graph_data = open('data.txt', 'r').read()
lines = graph_data.split('\n')
xs = []
ys = []
for line in lines:
if len(line) > 1:
x, y = line.split(',')
xs.append(x)
ys.append(y)
ax1.clear()
axi.plot(xs, ys)
ani = animation.FuncAnimation(fig, animate, interval=1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment