最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python matplotlib 動(dòng)畫繪制詳情

 更新時(shí)間:2022年09月01日 09:38:17   作者:Chandler_river  
這篇文章主要介紹了Python matplotlib 動(dòng)畫繪制,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,感興趣的小伙伴可以參考一下

最最簡單的操作

import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.subplots()
 
x = np.linspace(0,10,100)
y = np.sin(x)
 
while True:
    ax.plot(x,y)
    plt.pause(1)
    ax.cla()      
    x += np.pi/30    
    y = np.sin(x)

有人會(huì)問,為什么不能直接 用 plot 替代 ax 呢?

好問題,你可以一試,會(huì)發(fā)現(xiàn)這玩意沒法關(guān)掉 。。 當(dāng)然  ctrl + C等暴力手段是任何時(shí)候都o(jì)k的

Animation類

FuncAnimation

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
fig = plt.figure()
ax = fig.subplots()
 
x = np.linspace(0,10,100)
y = np.sin(x)
ax.set_aspect(3)
ax.plot(x,y,'-.',c='red',label="the old one")
line = ax.plot(x,y,c='green')
plt.legend()
 
def fun(i):  
    global x    
    x += 0.1
    y = np.sin(x)
    line[0].set_ydata(y)
    return line
 
 
animation = FuncAnimation(fig,fun,interval=100) 
plt.show() 

這就有兩個(gè)問題需要解決一下

第一個(gè):line到底是什么類型的東西

type(line)
<class 'list'>

明顯,這就是。。列表。

第二個(gè):set_data;set_xdata;set_ydata

你可以自己更改一下試試看,結(jié)果是顯而易見的

ArtistAnimation

它的好處是你不要費(fèi)盡心機(jī)去想一個(gè)可能 勾八 的函數(shù)了

它的壞處是 :

一個(gè)能用函數(shù)表示的動(dòng)畫 為什么要在新增一個(gè)列表才能表達(dá)呢?

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import ArtistAnimation
fig = plt.figure()
ax = fig.subplots()
 
frames = []
x = np.linspace(0,np.pi*2,10)
for i in range(20):
    x += np.pi*2/20
    y = np.sin(x)
    frames.append(ax.plot(y,'-.',c='red'))
 
animation = ArtistAnimation(fig,frames,interval=100)
plt.show() 

很好!現(xiàn)在只需要保存動(dòng)畫就圓滿了

動(dòng)畫保存

.save()函數(shù)

filename畫文件名+后綴
fps動(dòng)畫每秒的幀數(shù)   默認(rèn)值為 原動(dòng)畫的幀數(shù)
dpi動(dòng)畫每英寸的點(diǎn)數(shù) 默認(rèn)值為 原動(dòng)畫的點(diǎn)數(shù)
codec編碼格式 默認(rèn)值為’h264’

filename畫文件名+后綴fps動(dòng)畫每秒的幀數(shù)   默認(rèn)值為 原動(dòng)畫的幀數(shù)dpi動(dòng)畫每英寸的點(diǎn)數(shù) 默認(rèn)值為 原動(dòng)畫的點(diǎn)數(shù)codec編碼格式 默認(rèn)值為’h264’

animation.save("1.gif")

到此這篇關(guān)于Python matplotlib 動(dòng)畫繪制的文章就介紹到這了,更多相關(guān)Python matplotlib 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

保定市| 堆龙德庆县| 抚顺县| 浦东新区| 定州市| 册亨县| 沧源| 丹寨县| 汾阳市| 普兰店市| 柳江县| 永登县| 军事| 四平市| 东台市| 中西区| 澄城县| 龙胜| 绩溪县| 佛教| 井陉县| 华宁县| 泰来县| 泗水县| 怀宁县| 财经| 化州市| 宁陵县| 洞头县| 阿巴嘎旗| 乐亭县| 库伦旗| 肇东市| 梅河口市| 海兴县| 宁夏| 壶关县| 临清市| 宁海县| 台东县| 虞城县|