栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Matplotlib 绘制 3D 曲面动画

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Matplotlib 绘制 3D 曲面动画

加载数据

数据下载地址 123 KB

z np.load( ./data.npy )
转换数据

x轴和y轴的数据。

x np.linspace(0, 31, 32) 
x, y np.meshgrid(x, y)
定义数据更新数据

函数的三个参数

动画要更新的次数 帧 可以当作是数据的索引更新的数据画布
def update_map(num, z, plot):
 plot[0].remove()
 plot[0] ax.plot_surface(x, y, z[num], cmap cm.Oranges, linewidth 0)

然后定义画布和一些参数

fig, ax plt.subplots(tight_layout True, figsize (6, 6), subplot_kw dict(projection 3d ))
plot [ax.plot_surface(x, y, z[0], cmap cm.Oranges, linewidth 0)]
ax.set_xlim(0, 31)
ax.set_ylim(0, 31)
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
ax.axis( off )
ax.plot([0, 0], [0, 31], [0, 0], c black )
ax.plot([0, 31], [0, 0], [0, 0], c black )
ax.plot([31, 0], [31, 31], [0, 0], c black )
ax.plot([31, 31], [0, 31], [0, 0], c black )
ax.view_init(50, 120)
绘制 3D 曲面动画并显示
ani animation.FuncAnimation(
 fig, update_map, 30, interval 100, fargs (z, plot), repeat True)
plt.show()
保存为gif

需要安装一下imagemagick 谷歌/百度安装一下先。

ani.save( teaser .gif , writer imagemagick ,fps 10)
完整代码
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import cm, rcParams
z np.load( ./data.npy )
x np.linspace(0, 31, 32) 
x, y np.meshgrid(x, y)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/266828.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号