#python-3.x #matplotlib
Вопрос:
Я хотел иметь возможность обновлять график FuncAnimation
с помощью каждой итерации «x», но он открывал «x» количество окон без точек данных.
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
%matplotlib qt
class foo():
def __init__(self):
self.T = np.zeros(10)
self.Q = np.zeros(10)
self.Tset = np.zeros(10)
def main(self):
T = 6
for i in range(len(self.T)):
self.Tset[i] = np.random.randint(0,10)
self.T[i] = T
self.Q[i] = np.random.randint(0,100)
new_T = np.random.randint(0,10)
T = new_T
self.render()
def render(self):
fig, self.ax = plt.subplots(2,1)
ani = FuncAnimation(fig, self.animate())
def animate(self):
T = self.T
Tset = self.Tset
Q = self.Q
plt.clf()
self.ax[0].plot(T)
self.ax[0].plot(Tset)
self.ax[1].plot(Q)
plt.show()
foo = foo()
foo.main()
foo.render()
Любой совет был бы очень признателен.