程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了当 blit 设置为 True 时,Matplotlib Animate 不呈现大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_607_0@如何解决当 blit 设置为 True 时,Matplotlib Animate 不呈现? 开发过程中遇到当 blit 设置为 True 时,Matplotlib Animate 不呈现的问题如何解决?下面主要结合日常开发的经验,给出你关于当 blit 设置为 True 时,Matplotlib Animate 不呈现的解决方法建议,希望对你解决当 blit 设置为 True 时,Matplotlib Animate 不呈现有所启发或帮助;

我正在尝试在函数中使用 animation.FuncAnimation。目标是在两体模型中对轨道进行动画演示。

调用动画的函数设置如下:

os = SMOTE(random_state=0)
X_Train,X_test,y_Train,y_test = Train_test_split(X,y,test_size=0.3,random_state=0)
columns = X_Train.columns
os_data_X,os_data_y=os.fit_sample(X_Train,y_Train)

def plot_animate(r,bod_rad,steps,dt): #Setup plot environment fig = plt.figure(figsize=(10,10)) ax = fig.add_subplot(111,projection='3d') max_val = np.max(np.abs(r)) ax.set_xlim([-max_val,max_val]) ax.set_ylim([-max_val,max_val]) ax.set_zlim([-max_val,max_val]) #Plot BACkground and body to orbit ax = ploT_Bckground(ax,bod_rad) #Setup initial position and current position ax.plot([r[0,0]],[r[0,1]],2]],'ko',label='StarTing position',zorder=20) orb,= ax.plot(r[0,0],r[0,1],2],'k--',label='trajectory',zorder=10) pos,= ax.plot([r[0,'go',label='Current position',zorder=10) #Animate trajectory anime = animation.FuncAnimation(fig,orbit_anim,fargs=(ax,r,orb,pos),\ frames=steps,interval=dt,blit=TruE) plt.legend() plt.show() 添加一个球体和一个起点的图。 plT_Background 如下所示:

orbit_anim

当 blit 为 false 时,代码按预期工作。绿色的“当前位置”点引导轨道轨迹线并被渲染。 但是,当 blit 设置为 true 时,代码仍然有效,但不再自动呈现绿色的“当前位置”。只有当我改变 3d 绘图视图的视角时才会出现,不再引导轨迹。

@H_607_0@解决方法

错误是因为我没有更新值,而是再次渲染整条线,我猜这会覆盖 pos 艺术家对象的渲染。当我切换到更改数据时,渲染工作了:

def orbit_anim(frame,ax,r,orb,pos):
    orb.set_data(r[:frame+1,0],r[:frame+1,1])
    orb.set_3d_properties(r[:frame+1,2],'z')    
    pos.set_data(r[frame,r[frame,1])
    pos.set_3d_properties(r[frame,'z')
    return orb,pos

大佬总结

以上是大佬教程为你收集整理的当 blit 设置为 True 时,Matplotlib Animate 不呈现全部内容,希望文章能够帮你解决当 blit 设置为 True 时,Matplotlib Animate 不呈现所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。