1 Star 0 Fork 2

GaoXL/My Machine Learning

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Matplotlib 3D.py 1.91 KB
一键复制 编辑 原始数据 按行查看 历史
shiyuxin233 提交于 2020-08-16 19:16 . '学Matplotlib时候写的'
from mpl_toolkits import mplot3d
from matplotlib.pylab import *
plt.style.use('ggplot')
fig, ax = plt.figure(), plt.axes(projection='3d')
# 画一个莫比乌斯带
theta = linspace(0, 2 * pi, 30)
w = linspace(-0.25, 0.25, 8)
w, theta = meshgrid(w, theta)
phi = 0.5 * theta
r = 1 + w * cos(phi)
x = ravel(r * cos(theta))
y = ravel(r * sin(theta))
z = ravel(w * sin(phi))
from matplotlib.tri import Triangulation
tri = Triangulation(ravel(w), ravel(theta))
ax.plot_trisurf(x, y, z, triangles=tri.triangles, cmap='viridis')
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
ax.set_zlim(-1, 1)
fig.colorbar(cm.ScalarMappable())
fig.show()
# 曲面三角剖分
# theta = 2 * pi * random(1000)
# r = 6 * random(1000)
# x = r * sin(theta)
# y = r * cos(theta)
# z = sin(sqrt(x ** 2 + y ** 2))
#
# ax.plot_trisurf(x, y, z, cmap='viridis')
# fig.colorbar(cm.ScalarMappable())
# 在曲面图中使用极坐标
# r = linspace(-5, 5, 30)
# theta = np.linspace(0, 0.75 * pi, 40)
# r, theta = meshgrid(r, theta)
#
# X = r * sin(theta)
# Y = r * cos(theta)
# Z = sin(sqrt(X ** 2 + Y ** 2))
# ax.plot_surface(X, Y, Z, cmap='viridis')
# fig.colorbar(cm.ScalarMappable())
# 网格图和曲面图
# x = linspace(-5, 5, 100)
# X, Y = meshgrid(x, x)
# Z = sin(sqrt(X ** 2 + Y ** 2))
# ax.plot_surface(X, Y, Z, cmap='viridis')
# ax.set_title('surface')
# 等高线图
# x = linspace(-5, 5, 100)
# X, Y = meshgrid(x, x)
# Z = sin(sqrt(X ** 2 + Y ** 2))
#
# ax.contour3D(X, Y, Z, 100, cmap='viridis')
# ax.set_xlabel('x')
# ax.set_ylabel('y')
# ax.set_zlabel('z')
# ax.view_init(60, 35) # 调整视角
# fig.colorbar(cm.ScalarMappable())
# line and dot
# x = linspace(0, 10, 1000)
# y = sin(x)
# z = cos(x)
#
# ax.plot3D(x, y, z)
#
# x_data = 15 * np.random.random(100)
# y_data = sin(x_data) + 0.1 * np.random.randn(100)
# z_data = cos(x_data) + 0.1 * np.random.randn(100)
#
# ax.scatter3D(x_data, y_data, z_data, c=z_data, cmap='viridis')
#
# fig.colorbar(cm.ScalarMappable())
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/getwellman/My-Machine-Learning.git
[email protected]:getwellman/My-Machine-Learning.git
getwellman
My-Machine-Learning
My Machine Learning
master

搜索帮助