这是一个示例代码,它涉及到我的问题:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
fig, ax = plt.subplots()
xdata, ydata = [], []
ln, = plt.plot([], [], '-o', animated=True)
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)
ax.set_xlim(np.amin(xdata), np.amax(xdata))
return ln,
ani = FuncAnimation(fig, update, frames=np.linspace(0, 2*np.pi, 128),
init_func=init, blit=True)
plt.show()
如果我设置
blit=True
,则数据点会按照我想要的方式绘制。然而,x轴标签/刻度仍保持静态。如果我设置
blit=False
,那么x轴标签和刻度会按照我想要的方式更新。然而,没有任何数据点被绘制出来。如何同时获得绘制的数据(正弦曲线)和x轴数据更新?
animated=False
和blit=False
。稍后我可能会写一篇完整的答案并解释为什么这样做。 - ImportanceOfBeingErnest