1 繪制2D動畫(animation)
????????Matplotlib是一個Python繪圖庫,它提供了豐富的繪圖功能,包括繪制動畫。要繪制動畫,Matplotlib提供了
FuncAnimation
類,允許您創(chuàng)建基于函數(shù)的動畫。下面是一個詳細(xì)的Matplotlib動畫示例,演示了如何創(chuàng)建一個簡單的動畫。文章來源地址http://www.zghlxwxcb.cn/news/detail-723237.html
示例1:Matplotlib繪制一個簡單的正弦波動畫 :
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
# 創(chuàng)建一個空白圖形
fig, ax = plt.subplots()
# 創(chuàng)建一個空白線條,稍后將在動畫中更新
line, = ax.plot([], [], lw=2)
# 設(shè)置坐標(biāo)軸范圍
ax.set_xlim(0, 2*np.pi)
ax.set_ylim(-1, 1)
# 初始化函數(shù),用于創(chuàng)建空白圖形
def init():
line.set_data([], [])
return line,
# 動畫更新函數(shù),在每一幀中更新線條數(shù)據(jù)
def update(frame):
x = np.linspace(0, 2*np.pi, 1000)
y = np.sin(2*np.pi * (x - 0.01 * frame))
line.set_data(x, y)
return line,
# 創(chuàng)建動畫對象,傳遞初始化函數(shù)和更新函數(shù)
ani = FuncAnimation(fig, update, frames=200, init_f
文章來源:http://www.zghlxwxcb.cn/news/detail-723237.html
到了這里,關(guān)于【100天精通Python】Day67:Python可視化_Matplotlib 繪制動畫,2D、3D 動畫 示例+代碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!