This is my code
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
style.use('fivethirtyeight')
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 = map(int, line.split(','))
xs.append(x)
ys.append(y)
ax1.clear()
ax1.plot(xs,ys)
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ani = animation.FuncAnimation(fig, animate, interval=30000)
plt.show()
data.txt and data2.txt are just like:
0,1040
1,1074
2,1106
3,1123
4,1093
5,1067
6,1099
7,1121
8,1139
Now I have another data2.txt file and I need to plot the graph in the same figure like "overlapping". How to do this with this code?