matplotlib、Altair和Plotly动画的扩展
gif的Python项目详细描述
关于
Altair、matplotlib和Plotly动画的扩展名。在
安装
gif安装在命令行:
pip install -U gif
根据您计划使用的gif风格,您可能需要一些附加的依赖项:
^{pr2}$Note:gif[altair]使用Selenium,这需要正确配置chromedriver或{a6}。在
使用(牵牛星)
导入和数据:
importrandomimportaltairasaltimportpandasaspdimportgifdf=pd.DataFrame({'t':list(range(10))*10,'x':[random.randint(0,100)for_inrange(100)],'y':[random.randint(0,100)for_inrange(100)]})
用gif.frame
和修饰plot函数返回一个牵牛星对象:
@gif.framedefplot(i):d=df[df['t']==i]chart=alt.Chart(d).encode(x=alt.X('x',scale=alt.Scale(domain=(0,100))),y=alt.Y('y',scale=alt.Scale(domain=(0,100)))).mark_circle()returnchart
用一个标准的for
循环构建一堆“框架”:
frames=[]foriinrange(10):frame=plot(i)frames.append(frame)
指定每帧与保存之间的持续时间:
gif.save(frames,'example.gif',duration=100,unit="ms",between="frames")
用法(matplotlib)
导入和数据:
importrandomfrommatplotlibimportpyplotaspltimportgifx=[random.randint(0,100)for_inrange(100)]y=[random.randint(0,100)for_inrange(100)]
(可选)将每英寸点数分辨率设置为300:
gif.options.matplotlib["dpi"]=300
用gif.frame
装饰plot函数(并且不返回任何内容):
@gif.framedefplot(i):xi=x[i*10:(i+1)*10]yi=y[i*10:(i+1)*10]plt.scatter(xi,yi)plt.xlim((0,100))plt.ylim((0,100))
用一个标准的for
循环构建一堆“框架”:
frames=[]foriinrange(10):frame=plot(i)frames.append(frame)
指定整个gif的持续时间:
gif.save(frames,'example.gif',duration=3.5,unit="s",between="startend")
用法(绘图)
导入和数据:
importrandomimportplotly.graph_objectsasgoimportpandasaspdimportgifdf=pd.DataFrame({'t':list(range(10))*10,'x':[random.randint(0,100)for_inrange(100)],'y':[random.randint(0,100)for_inrange(100)]})
用gif.frame
和修饰plot函数返回一个绘出的图形:
@gif.framedefplot(i):d=df[df['t']==i]fig=go.Figure()fig.add_trace(go.Scatter(x=d["x"],y=d["y"],mode="markers"))fig.update_layout(width=500,height=300)returnfig
用一个标准的for
循环构建一堆“框架”:
frames=[]foriinrange(10):frame=plot(i)frames.append(frame)
指定每个帧与保存之间的持续时间(毫秒):
gif.save(frames,'example.gif',duration=100)
画廊(牛郎星)
单击任意图像查看源代码
图库(matplotlib)
单击任意图像查看源代码
^{tb2}$画廊(情节)
单击任意图像查看源代码
如果你有一个你认为应该在画廊里的蠢货动画,提交一个公关!在
- 项目
标签: