栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

用Matplotlib绘制椭球体

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

用Matplotlib绘制椭球体

下面是如何通过球坐标实现的:

from mpl_toolkits.mplot3d import Axes3Dimport matplotlib.pyplot as pltimport numpy as npfig = plt.figure(figsize=plt.figaspect(1))  # Square figureax = fig.add_subplot(111, projection='3d')coefs = (1, 2, 2)  # Coefficients in a0/c x**2 + a1/c y**2 + a2/c z**2 = 1 # Radii corresponding to the coefficients:rx, ry, rz = 1/np.sqrt(coefs)# Set of all spherical angles:u = np.linspace(0, 2 * np.pi, 100)v = np.linspace(0, np.pi, 100)# Cartesian coordinates that correspond to the spherical angles:# (this is the equation of an ellipsoid):x = rx * np.outer(np.cos(u), np.sin(v))y = ry * np.outer(np.sin(u), np.sin(v))z = rz * np.outer(np.ones_like(u), np.cos(v))# Plot:ax.plot_surface(x, y, z,  rstride=4, cstride=4, color='b')# Adjustment of the axes, so that they all have the same span:max_radius = max(rx, ry, rz)for axis in 'xyz':    getattr(ax, 'set_{}lim'.format(axis))((-max_radius, max_radius))plt.show()

上面的程序实际上生成了一个更好看的“正方形”图形。这个解决方案的灵感来自
示例
在Matplotlib的画廊.



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/660660.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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