-
-
Save Lusimba/ef6d089fd706f6d141adaa6f6d66419f to your computer and use it in GitHub Desktop.
This file contains 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
#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