您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Matplotlib动画中更新X轴标签

在Matplotlib动画中更新X轴标签

首先涉及到笔迹:笔迹仅应用于轴的内容。它将影响轴的内部,但不影响外部轴的装饰器。因此,如果使用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()
其他 2022/1/1 18:34:20 有403人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶