Python 3.x 在Matplotlib'中的动画期间传递参数;funcs动画方法

Python 3.x 在Matplotlib'中的动画期间传递参数;funcs动画方法,python-3.x,matplotlib,Python 3.x,Matplotlib,在fargs元组参数中,是否有方法将不断变化的参数传递给FuncAnimation函数? 或者可以从animate方法读取类的局部变量 我在网上找到了这个例子,它似乎可以做到……但我无法做类似的事情,局部变量被阻止,直到不再使用该变量,动画才开始 import datetime as dt import matplotlib.pyplot as plt import matplotlib.animation as animation import tmp102 # Create figure

在fargs元组参数中,是否有方法将不断变化的参数传递给FuncAnimation函数? 或者可以从animate方法读取类的局部变量

我在网上找到了这个例子,它似乎可以做到……但我无法做类似的事情,局部变量被阻止,直到不再使用该变量,动画才开始

import datetime as dt
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import tmp102

# Create figure for plotting
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
xs = []
ys = []

# Initialize communication with TMP102
tmp102.init()

# This function is called periodically from FuncAnimation
def animate(i, xs, ys):
# Read temperature (Celsius) from TMP102
temp_c = round(tmp102.read_temp(), 2)

# Add x and y to lists
xs.append(dt.datetime.now().strftime('%H:%M:%S.%f'))
ys.append(temp_c)

# Limit x and y lists to 20 items
xs = xs[-20:]
ys = ys[-20:]

# Draw x and y lists
ax.clear()
ax.plot(xs, ys)

# Format plot
plt.xticks(rotation=45, ha='right')
plt.subplots_adjust(bottom=0.30)
plt.title('TMP102 Temperature over Time')
plt.ylabel('Temperature (deg C)')

# Set up plot to call animate() function periodically
ani = animation.FuncAnimation(fig, animate, fargs=(xs, ys), interval=1000)
plt.show()