Matplotlib:mpl_toolkits.mplot3d工具包


簡介

  • 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
來源:簡書
簡書著作權歸作者所有,任何形式的轉載都請聯系作者獲得授權並注明出處。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM