Я просто тестирую функцию анимации matplotlib.Я строю график использования процессора и времени с подвижной осью X.Ось изменяется, но график кажется пустым.Я думаю, что мне нужно сделать длину больше 1, потому что он не может построить отдельные точки?Как мне решить эту проблему?Спасибо!
import time
import psutil
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
ax = fig.add_subplot(111)
fig.show()
def animate(i):
x=[]
y=[]
x.append(time.time())
y.append(psutil.cpu_percent())
print(x)
print(y)
ax.clear()
ax.plot(x,y,color='b')
ax.set_xlim(left=max(0,i-5),right=(i+5))
ani=animation.FuncAnimation(fig,animate,interval=500)
plt.show()