Skip to content

Instantly share code, notes, and snippets.

@parulnith
Last active May 29, 2020 18:00
Show Gist options
  • Save parulnith/0c02c6428af9b11aee24d7514ac36627 to your computer and use it in GitHub Desktop.
Save parulnith/0c02c6428af9b11aee24d7514ac36627 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