-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotGraph.py
More file actions
43 lines (35 loc) · 880 Bytes
/
Copy pathplotGraph.py
File metadata and controls
43 lines (35 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import matplotlib.pyplot as plt, mpld3
import matplotlib.animation as animation
from matplotlib import style
import time
import json
style.use("ggplot")
figure = plt.figure()
subpl = figure.add_subplot(1,1,1)
def animate(i):
pullData = open("twitter-out.txt","r").read()
lines = pullData.split('\n')
xl = []
yl = []
x = 0
y = 0
for l in lines[-500:]:
x += 1
if "pos" in l:
y += 1
elif "neg" in l:
y -= 1
xl.append(x)
yl.append(y)
subpl.clear()
subpl.plot(xl,yl)
anim = animation.FuncAnimation(figure, animate, interval=1000)
# plt.show()
try:
json01 = json.dumps(mpld3.fig_to_dict(figure))
# print (json01)
# mpld3.fig_to_html(figure, template_type="simple")
# mpld3.save_html(figure,"test.html")
except Exception as e:
print (e)
# mpld3.show()