Python 用matplotlib实现实时图形
我正在尝试创建一个实时图形,该图形根据用python编写的文本文件中的信息进行实时更新我每次运行代码时都会遇到问题图形窗口会打开,但它总是冻结,并说没有响应有人能帮我解决此问题吗下面是我的代码Python 用matplotlib实现实时图形,python,matplotlib,animation,Python,Matplotlib,Animation,我正在尝试创建一个实时图形,该图形根据用python编写的文本文件中的信息进行实时更新我每次运行代码时都会遇到问题图形窗口会打开,但它总是冻结,并说没有响应有人能帮我解决此问题吗下面是我的代码 import matplotlib.pyplot as plt import matplotlib.animation as animation import time fig = plt.figure() ax1 = fig.add_subplot(1,1,1) def animate(i):
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
def animate(i):
pullData = open("example.txt","r").read()
dataArray = pullData.split('\n')
xar = []
yar = []
for eachLine in dataArray:
if len(eachLine)>1:
x,y = eachLine.split(',')
xar.append(int(x))
yar.append(int(y))
ax1.clear()
ax1.plot(xar,yar)
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()
count = 14
import random
while(count > 200):
with open("example.txt", "a") as text_file:
count+=1
text_file.write(str(count) + "," + str(random.randint(1,101)))
text_file.write("\n")