mplot3d 工具包#

使用 mplot3d 工具包生成三维绘图。

本教程展示了各种三维绘图。点击图表可查看每个完整的图库示例及其生成图表的代码。

通过将 projection="3d" 关键字参数传递给 Figure.add_subplot,可以创建三维坐标轴(Axes3D 类)。

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(projection='3d')

与二维子图一样,可以在同一张图表上添加多个三维子图。

../../../_images/sphx_glr_subplot3d_001.png

3.2.0 版本中的变化: 在 Matplotlib 3.2.0 之前,需要显式导入 mpl_toolkits.mplot3d 模块,才能使 '3d' 投影生效于 Figure.add_subplot

有关 mplot3d 工具包的更多信息,请参阅 mplot3d 常见问题

线图#

有关 API 文档,请参阅 Axes3D.plot

../../../_images/sphx_glr_lines3d_001.png

散点图#

有关 API 文档,请参阅 Axes3D.scatter

../../../_images/sphx_glr_scatter3d_001.png

线框图#

有关 API 文档,请参阅 Axes3D.plot_wireframe

../../../_images/sphx_glr_wire3d_001.png

曲面图#

有关 API 文档,请参阅 Axes3D.plot_surface

../../../_images/sphx_glr_surface3d_001.png

三角曲面图#

有关 API 文档,请参阅 Axes3D.plot_trisurf

../../../_images/sphx_glr_trisurf3d_001.png

等高线图#

有关 API 文档,请参阅 Axes3D.contour

../../../_images/sphx_glr_contour3d_001.png

填充等高线图#

有关 API 文档,请参阅 Axes3D.contourf

../../../_images/sphx_glr_contourf3d_001.png

1.1.0 版本新增: 第二个 contourf3d 示例中展示的功能是由于 1.1.0 版本的错误修复而启用的。

填充三维线条之间#

有关 API 文档,请参阅 Axes3D.fill_between

../../../_images/sphx_glr_fillbetween3d_001.png

自 3.10 版本新增。

多边形图#

有关 API 文档,请参阅 Axes3D.add_collection3d

../../../_images/sphx_glr_polys3d_001.png

条形图#

有关 API 文档,请参阅 Axes3D.bar

../../../_images/sphx_glr_bars3d_001.png

Quiver#

有关 API 文档,请参阅 Axes3D.quiver

../../../_images/sphx_glr_quiver3d_001.png

三维空间中的二维绘图#

../../../_images/sphx_glr_2dcollections3d_001.png

文本#

有关 API 文档,请参阅 Axes3D.text

../../../_images/sphx_glr_text3d_001.png