matplotlib提供了animation模块实现动态更新数据,请看下面的例子。
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from matplotlib.animation import FuncAnimation >>> fig, ax = plt.subplots() >>> xdata, ydata = [], [] >>> ln, = ax.plot([], [], 'r-', animated=False) >>> def init(): ax.set_xlim(0, 2*np.pi) ax.set_ylim(-1, 1) return ln, >>> def update(frame): xdata.append(frame) ydata.append(np.sin(frame)) ln.set_data(xdata, ydata) return ln,