Skip to content

Instantly share code, notes, and snippets.

@Lusimba
Forked from parulnith/live_graph.py
Created September 15, 2019 07:00
Show Gist options
  • Save Lusimba/ef6d089fd706f6d141adaa6f6d66419f to your computer and use it in GitHub Desktop.
Save Lusimba/ef6d089fd706f6d141adaa6f6d66419f to your computer and use it in GitHub Desktop.
#importing libraries
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
#creating a subplot
ax1 = fig.add_subplot(1,1,1)
def animate(i):
data = open('stock.txt','r').read()
lines = data.split('\n')
xs = []
ys = []
for line in lines:
x, y = line.split(',') # Delimiter is comma
xs.append(float(x))
ys.append(float(y))
ax1.clear()
ax1.plot(xs, ys)
plt.xlabel('Date')
plt.ylabel('Price')
plt.title('Live graph with matplotlib')
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