zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Matplotlib:mpl_toolkits.mplot3d工具包

matplotlib 工具包
2023-09-14 08:58:40 时间

简介

  • mpl_toolkits.mplot3d是Matplotlib里面专门用来画三维图的工具包,官方指南请点击此处《mplot3d tutorial》

使用

导入
  • 使用from mpl_toolkits.mplot3d import *或者import mpl_toolkits.mplot3d as p3d
画图
  • 有两种方式
fig = plt.figure()
ax = p3d.Axes3D(fig)

或者

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
  • 画三维图需要先得到一个Axes3D对象,上面两种方式得到的ax都是Axes3D对象,接下来就可以调用函数在ax上画图了。如下(IPython):
In [1]: %matplotlib inline
        import numpy as np
        import matplotlib.pyplot as plt
        import mpl_toolkits.mplot3d as p3d

        fig = plt.figure()
        ax = p3d.Axes3D(fig)

        z = np.linspace(0, 15, 1000)
        x = np.sin(z)
        y = np.cos(z)
        ax.plot(x, y, z, 'green')
效果如下:


作者:ACphart
链接:https://www.jianshu.com/p/b563920fa7a8
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。