在Python的matplotlib包中使用动画重新缩放轴

在Python的matplotlib包中使用动画重新缩放轴,python,animation,matplotlib,Python,Animation,Matplotlib,在python中使用matplotlib.animation使轴与动画一起动态自动缩放时遇到一些问题。以下是我的代码中的一个例外: def _update_plot(i,fig,scat): ax.relim() ax.autoscale_view() scat.set_offsets(np.array([x[i],y[i]])) return scat, fig = plt.figure() ax=fig.add_subplot(111,autoscale_

在python中使用matplotlib.animation使轴与动画一起动态自动缩放时遇到一些问题。以下是我的代码中的一个例外:

def _update_plot(i,fig,scat):
    ax.relim()
    ax.autoscale_view()
    scat.set_offsets(np.array([x[i],y[i]]))
    return scat,

fig = plt.figure()

ax=fig.add_subplot(111,autoscale_on=True)
ax.grid()

x=[x0]
y=[y0]
vx=[vx0]
vy=[vy0]
for t in range(10000):
    PV=getPV(x[-1],y[-1],vx[-1],vy[-1])
    x.append(PV[0])
    y.append(PV[1])
    vx.append(PV[2])
    vy.append(PV[3])

scat = plt.scatter(x=x0,y=y0,c=('r','b','r'))
scat.set_alpha(0.8)

anim = animation.FuncAnimation(fig,_update_plot,fargs=(fig,scat),frames=10000,interval=100)

plt.show()

relim
似乎只是将限制重置为非常小的默认限制,即0.05到-0.05。任何关于如何使轴在每次更新时适当地重新缩放的建议都将不胜感激。

几个问题:1)什么是
?应该是
ax吗?2) 看起来你总是只在
set_offset`中设置一个值,这真的是你想要的行为吗?哦,呜呜。是的,那应该是斧头。谢谢你提醒我!然而,以前的问题仍然存在?有什么建议吗?几个问题:1)什么是轴?应该是
ax吗?2) 看起来你总是只在
set_offset`中设置一个值,这真的是你想要的行为吗?哦,呜呜。是的,那应该是斧头。谢谢你提醒我!然而,以前的问题仍然存在?有什么建议吗?