首先涉及到笔迹:笔迹仅应用于轴的内容。它将影响轴的内部,但不影响外部轴的装饰器。因此,如果使用blit=True
轴,则装饰器不会更新。或反之,如果要缩放比例,则需要使用blit=False
。
现在,在问题的情况下,这导致未画线。原因是该行的animated
属性设置为True
。但是,默认情况下不会绘制“动画”艺术家。该属性实际上是用于发条。但是如果不执行blitting,则将导致艺术家既不被绘画也不被blit。最好将此属性称为“ property”blit_include
或类似名称,以避免名称混淆。 不幸的是,它看起来也没有充分的文献记载。但是,您会在源代码中找到一条注释,说
# if the artist is animated it does not take normal part in the
# draw stack and is not expected to be drawn as part of the normal
# draw loop (when not saving) so do not propagate this change
因此,总的来说,除非您使用blitting,否则可以忽略此参数的存在。即使使用blitting,在 大多数情况下 也可以忽略它,因为该属性始终在内部设置。
在这里总结解决方案是不使用animated
和不使用blit
。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
fig, ax = plt.subplots()
xdata, ydata = [], []
ln, = plt.plot([], [], '-o')
def init():
ax.set_xlim(0, 2*np.pi)
ax.set_ylim(-1, 1)
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))
ani = FuncAnimation(fig, update, frames=np.linspace(0, 2*np.pi, 128),
init_func=init)
plt.show()