校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > 使用numpngw和matplotlib生成png動畫的示例代碼

使用numpngw和matplotlib生成png動畫的示例代碼

熱門標簽:外呼電信系統 熱門電銷機器人 okcc外呼系統怎么調速度 惠州龍門400電話要怎么申請 河南虛擬外呼系統公司 上海企業外呼系統 電話機器人哪里有賣 智能機器人電銷神器 萬利達百貨商場地圖標注

在matplotlib官網看到了第三方庫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
from matplotlib import pyplot as plt
import matplotlib.animation as animation
from 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=[i for i in zip(x,y)]

def plot_love(data):
  x, y = data
  plt.scatter(x, y, 60, c="r", alpha=0.7, marker=r"$\heartsuit$")
fig=plt.figure(figsize=(5, 3), dpi=100)
plt.axis("off")

writer = AnimatedPNGWriter(fps=12)
animator = animation.FuncAnimation(fig, plot_love, frames=data)
animator.save("love.png", writer=writer)

使用matplotlib和pillow實現gif動畫

from matplotlib import pyplot as plt
import matplotlib.animation as animation
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=[i for i in zip(x,y)]

def plot_love(data):
  x, y = data
  plt.scatter(x, y, 60, c="r", alpha=0.7, marker=r"$\heartsuit$")

fig=plt.figure(figsize=(5, 3), dpi=100)
plt.axis("off")
animator = animation.FuncAnimation(fig, plot_love, frames=data, interval=80)
animator.save("love.gif", writer='pillow')

關鍵代碼解讀

# 導入AnimatedPNGWriter
from numpngw import AnimatedPNGWriter

# 初始化AnimatedPNGWriter
writer = AnimatedPNGWriter(fps=12)
# 將save函數中的writer參數設為AnimatedPNGWriter實例
animator.save("love.png", writer=writer)

通過對比可知,使用 numpngw+matplotlib生成png動畫方式非常簡單,只用初始化AnimatedPNGWriter,在save函數中指定writer即可。

到此這篇關于使用numpngw和matplotlib生成png動畫的示例代碼的文章就介紹到這了,更多相關numpngw和matplotlib生成png動畫內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • Python使用matplotlib繪制動畫的方法
  • Python通過matplotlib繪制動畫簡單實例
  • Python使用Matplotlib實現雨點圖動畫效果的方法
  • matplotlib繪制動畫代碼示例
  • 如何基于Python Matplotlib實現網格動畫
  • 如何利用Matplotlib庫繪制動畫及保存GIF圖片

標簽:周口 綏化 綿陽 合肥 周口 百色 淮安 秦皇島

巨人網絡通訊聲明:本文標題《使用numpngw和matplotlib生成png動畫的示例代碼》,本文關鍵詞  使用,numpngw,和,matplotlib,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《使用numpngw和matplotlib生成png動畫的示例代碼》相關的同類信息!
  • 本頁收集關于使用numpngw和matplotlib生成png動畫的示例代碼的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 通渭县| 常山县| 景谷| 昌邑市| 嵩明县| 青岛市| 瓦房店市| 邯郸市| 四平市| 炉霍县| 错那县| 布尔津县| 清原| 革吉县| 延寿县| 古丈县| 泾阳县| 泸西县| 和政县| 芷江| 桑植县| 黑水县| 抚松县| 开江县| 汤原县| 汉阴县| 晋中市| 宜宾县| 息烽县| 江津市| 高陵县| 蒲城县| 阿拉善左旗| 龙里县| 中宁县| 临澧县| 河北省| 富顺县| 新乡市| 德庆县| 龙胜|