简介

  • 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')
效果如下:
Matplotlib:mpl_toolkits.mplot3d工具包


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

相关文章:

  • 2021-08-07
  • 2021-07-13
  • 2022-02-20
  • 2021-12-23
  • 2021-12-20
猜你喜欢
  • 2021-08-31
  • 2021-12-20
  • 2021-12-04
  • 2021-12-09
  • 2021-05-28
相关资源
相似解决方案