Python 3D曲面Surface自由
曲面图(Surface plot)用于展示包含 X、Y 和 Z 坐标的数据集。这里,X 和 Y 坐标通常代表地理坐标,如纬度和经度,而 Z 则代表某一位置的高度或其他数值,例如温度、压力等。这种图形通过在数据点之间插值生成表面,从而为数据提供了一个连续的、平滑的表现形式。
这里分享一个Python matplotlib实现3D Surface plot的案例,
# 17.1_01
# -*- encoding: utf-8 -*-
'''
未经过允许禁止转载!
@Author : 公众号: pythonic生物人
@Desc : 17.1 3D曲面图
'''import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# 核心代码
fig = plt.figure(figsize=(16, 12), dpi=250)
ax1 = fig.add_subplot(2, 2, 1, projection='3d')
surf1 = ax1.plot_surface(X, Y, Z1, cmap=cmaps, edgecolor='none') # 绘制波动曲面
fig.colorbar(surf1, ax=ax1, shrink=0.5, aspect=10)
ax1.set_title(titles[0], fontsize=15)
ax2 = fig.add_subplot(2, 2, 2, projection='3d')
surf2 = ax2.plot_surface(X2, Y2, Z2, cmap=cmaps, edgecolor='none',
shade=False) # 绘制周期性曲面
fig.colorbar(surf2, ax=ax2, shrink=0.5, aspect=10)
ax2.set_title(titles[1], fontsize=15)
ax3 = fig.add_subplot(2, 2, 3, projection='3d')
surf3 = ax3.plot_surface(X, Y, Z3, cmap=cmaps, edgecolor='none') # 绘制高斯曲面
fig.colorbar(surf3, ax=ax3, shrink=0.5, aspect=10)
ax3.set_title(titles[2], fontsize=15)
ax4 = fig.add_subplot(2, 2, 4, projection='3d')
surf4 = ax4.plot_surface(X4, Y4, Z4, cmap=cmaps, edgecolor='none') # 绘制圆球曲面
fig.colorbar(surf4, ax=ax4, shrink=0.5, aspect=10)
ax4.set_title(titles[3], fontsize=15)
plt.tight_layout()
plt.subplots_adjust(wspace=0.005, hspace=0.1)
plt.show()
-END-
本期内容「绘图数据+代码+代码详细解释」已上传(点击图片直达代码):
👉Python matplotlib保姆级教程 👉保姆级matplotlib教程—详细目录 👉Python seaborn保姆级教程 👉保姆级seaborn教程:详细目录
交流学习