• <tfoot id='u5Y4D'></tfoot>

      • <bdo id='u5Y4D'></bdo><ul id='u5Y4D'></ul>

    1. <small id='u5Y4D'></small><noframes id='u5Y4D'>

      <legend id='u5Y4D'><style id='u5Y4D'><dir id='u5Y4D'><q id='u5Y4D'></q></dir></style></legend>
      <i id='u5Y4D'><tr id='u5Y4D'><dt id='u5Y4D'><q id='u5Y4D'><span id='u5Y4D'><b id='u5Y4D'><form id='u5Y4D'><ins id='u5Y4D'></ins><ul id='u5Y4D'></ul><sub id='u5Y4D'></sub></form><legend id='u5Y4D'></legend><bdo id='u5Y4D'><pre id='u5Y4D'><center id='u5Y4D'></center></pre></bdo></b><th id='u5Y4D'></th></span></q></dt></tr></i><div id='u5Y4D'><tfoot id='u5Y4D'></tfoot><dl id='u5Y4D'><fieldset id='u5Y4D'></fieldset></dl></div>

      1. matplotlib 动画保存不遵守 blit=True 但它似乎在 plt.show() 中工作得很好

        matplotlib animation save is not obeying blit=True but it seems to work just fine in plt.show()(matplotlib 动画保存不遵守 blit=True 但它似乎在 plt.show() 中工作得很好)
              <bdo id='NnexX'></bdo><ul id='NnexX'></ul>

                <legend id='NnexX'><style id='NnexX'><dir id='NnexX'><q id='NnexX'></q></dir></style></legend>
                  <tbody id='NnexX'></tbody>
              1. <small id='NnexX'></small><noframes id='NnexX'>

                <i id='NnexX'><tr id='NnexX'><dt id='NnexX'><q id='NnexX'><span id='NnexX'><b id='NnexX'><form id='NnexX'><ins id='NnexX'></ins><ul id='NnexX'></ul><sub id='NnexX'></sub></form><legend id='NnexX'></legend><bdo id='NnexX'><pre id='NnexX'><center id='NnexX'></center></pre></bdo></b><th id='NnexX'></th></span></q></dt></tr></i><div id='NnexX'><tfoot id='NnexX'></tfoot><dl id='NnexX'><fieldset id='NnexX'></fieldset></dl></div>
                <tfoot id='NnexX'></tfoot>
                • 本文介绍了matplotlib 动画保存不遵守 blit=True 但它似乎在 plt.show() 中工作得很好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我对 Python 很陌生,正在尝试使用 matplotlib 为文本设置动画.使用了几个在线示例得出以下代码:

                  I'm quite new to Python and am trying to animate text using matplotlib. used several online examples to arrive at the following code:

                  import matplotlib.pyplot as plt
                  import matplotlib.animation as animation
                  
                  fig, ax = plt.subplots()
                  
                  plt.xlabel('Distance')
                  plt.ylabel('Height')
                  plt.title('Object Trajectory 
                  ')
                  
                  plt.legend(loc="upper right", markerscale=4, fontsize=10)
                  plt.grid()
                  
                  text=ax.text(3,1,'Moving Text', ha="left", va="bottom",clip_on=True,rotation=90,fontsize=15)    
                  text2=ax.text(0,1,'Moving Text', ha="left", va="bottom",clip_on=True,fontsize=15)    
                  
                  def init():
                      ax.set_xlim(0,10)
                      ax.set_ylim(0,10)
                      return text,text2
                  
                  def update(frame):        
                      #Moving a text
                      text=ax.text(3,1+(int(frame))/30,'Moving Text', ha="left", va="bottom",clip_on=True,rotation=90,fontsize=15)    
                      text2=ax.text(0+(int(frame))/30,1,'Moving Text', ha="left", va="bottom",clip_on=True,fontsize=15)    
                  
                      return text,text2
                  
                  anim = animation.FuncAnimation(fig, update, init_func=init, frames=120, interval=10, blit=True)
                  
                  anim.save('try_animation.mp4',dpi=160,fps=30, writer="ffmpeg")
                  
                  plt.show()
                  

                  所以当我在控制台中运行它时,我可以看到文本很好地移动.但是当我将它保存到 MP4 文件时,文本似乎并没有出现 blit.请帮忙.

                  So when I run it in console, I can see the texts moving nicely. But when I save it to a MP4 file the text doesn't seem to blit. Please Help.

                  谢谢

                  这是已保存视频文件的截图

                  推荐答案

                  您观察到的是预期的行为.Blitting 是一种用于仅刷新图形输出的一部分的技术.在 matplotlib 的情况下,不是绘制完整的图形,而是只刷新它的一部分,即轴内的区域,并且只绘制动画函数返回的那些艺术家.这允许在屏幕上具有更快的动画速度.

                  What you observe is the expected behaviour. Blitting is a technique used to refresh only part of a graphics output. In the matplotlib case, instead of drawing the complete figure, only part of it, namely the region inside the axes, is refreshed and only those artists returned by the animating function are drawn. This allows to have a faster animation speed on screen.

                  但是,在保存动画时,需要完整绘制每一帧.

                  因此,为了让文本移动,应该更新单个文本的位置,而不是一遍又一遍地创建新文本.这可以通过

                  So in order to have a text moving, one should rather update a single text's position, instead of creating new texts over and over again. This can be done with

                  text.set_position((x,y))
                  

                  该示例因此看起来像

                  import matplotlib.pyplot as plt
                  import matplotlib.animation as animation
                  
                  fig, ax = plt.subplots()
                  
                  plt.xlabel('Distance')
                  plt.ylabel('Height')
                  plt.title('Object Trajectory 
                  ')
                  plt.grid()
                  
                  text=ax.text(3,1,'Moving Text', ha="left", va="bottom",clip_on=True,rotation=90,fontsize=15)    
                  text2=ax.text(0,1,'Moving Text', ha="left", va="bottom",clip_on=True,fontsize=15)    
                  
                  def init():
                      ax.set_xlim(0,10)
                      ax.set_ylim(0,10)
                      return text,text2
                  
                  def update(frame):        
                      #Moving a text
                      text.set_position((3, 1+(int(frame))/30))
                      text2.set_position((0+(int(frame))/30,1))
                      return text,text2
                  
                  anim = animation.FuncAnimation(fig, update, init_func=init, frames=120, interval=10, blit=True)
                  
                  anim.save('try_animation.mp4',dpi=160,fps=30, writer="ffmpeg")
                  
                  plt.show()
                  

                  这篇关于matplotlib 动画保存不遵守 blit=True 但它似乎在 plt.show() 中工作得很好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                  Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                  Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                  How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                  Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                  Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)
                  <legend id='sqzQR'><style id='sqzQR'><dir id='sqzQR'><q id='sqzQR'></q></dir></style></legend>
                • <i id='sqzQR'><tr id='sqzQR'><dt id='sqzQR'><q id='sqzQR'><span id='sqzQR'><b id='sqzQR'><form id='sqzQR'><ins id='sqzQR'></ins><ul id='sqzQR'></ul><sub id='sqzQR'></sub></form><legend id='sqzQR'></legend><bdo id='sqzQR'><pre id='sqzQR'><center id='sqzQR'></center></pre></bdo></b><th id='sqzQR'></th></span></q></dt></tr></i><div id='sqzQR'><tfoot id='sqzQR'></tfoot><dl id='sqzQR'><fieldset id='sqzQR'></fieldset></dl></div>

                  <tfoot id='sqzQR'></tfoot>
                    <tbody id='sqzQR'></tbody>

                      • <small id='sqzQR'></small><noframes id='sqzQR'>

                          • <bdo id='sqzQR'></bdo><ul id='sqzQR'></ul>