使用numpngw与matplotlib怎么生成一个png动画

  介绍

今天就跟大家聊聊有关使用numpngw与matplotlib怎么生成一个png动画,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

numpngw概述

numpngw库可生成png静态图像和png动画。

<李>

通过write_png函数可以将numpy保存为png文件。

<李>

通过write_apng函数可以将数组序列保存为png动画(APNG)文件。

<李>

通过AnimatedPNGWriter类可以将matplotlib保存为png动画文件。

numpngw库的依赖包是numpy和setuptools。

使用numpngw和matplotlib生成png动画

numpngw + matplotlib实现png动画

import  numpy  as  np   得到matplotlib  import  pyplot  as  plt   import  matplotlib.animation  as 动画   得到numpngw  import  AnimatedPNGWriter      时间=t  np.linspace(0,, 6日,100)   时间=x  16, *, np.sin (t), * *, 3   y =, 13, *, np.cos (t),安康;5,*,np.cos (2, *, t),安康;2,*,np.cos (3, *, t),安康;np.cos (4, *, t)   data=https://www.yisu.com/zixun/(我因为我在zip (x, y)]      def plot_love(数据):   x, y=数据   plt。散射(x, y, 60, c=r,α=0.7,=r标志/heartsuit美元)   无花果=plt。图(figsize=(5,3), dpi=100)   plt.axis(“关闭”)      作家=AnimatedPNGWriter (fps=12)   动画师=动画。FuncAnimation(无花果、plot_love?数据)   animator.save(“爱。png”,作家=作家)

使用matplotlib和枕头实现gif动画

得到matplotlib  import  pyplot  as  plt   import  matplotlib.animation  as 动画   import  numpy  as  np      时间=t  np.linspace(0,, 6日,100)   时间=x  16, *, np.sin (t), * *, 3   y =, 13, *, np.cos (t),安康;5,*,np.cos (2, *, t),安康;2,*,np.cos (3, *, t),安康;np.cos (4, *, t)   data=https://www.yisu.com/zixun/(我因为我在zip (x, y)]      def plot_love(数据):   x, y=数据   plt。散射(x, y, 60, c=r,α=0.7,=r标志/heartsuit美元)      无花果=plt。图(figsize=(5,3), dpi=100)   plt.axis(“关闭”)   动画师=动画。FuncAnimation(无花果、plot_love?数据,间隔=80)   animator.save(“爱。gif”,作家=硗贰?

关键代码解读

#,导入AnimatedPNGWriter   得到numpngw  import  AnimatedPNGWriter      #,初始化AnimatedPNGWriter   时间=writer  AnimatedPNGWriter (fps=12)   #,将节省函数中的作家参数设为AnimatedPNGWriter实例   animator.save (“love.png",作家=作家)

看完上述内容,你们对使用numpngw与matplotlib怎么生成一个png动画有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。

使用numpngw与matplotlib怎么生成一个png动画