Python: Juypter 下繪製3D點圖

Juypter 下繪製3D點圖

目標

實現Juypter Notebook 下繪製3D圖形並可以使用鼠標拖動變換視角。

實現

  1. 生成x, y, z 軸的數據爲 [ 0 ~ 9 ]
  2. 使用 ax.scatter3D()繪製點圖,“c=z” 與cmap參數表示以z數據的值動態繪製漸變綠色。
  3. "%matplotlib notebook"開啓Jupyter Notebook 的鼠標交互變換視角。
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d

%matplotlib notebook

x = [ ]
y = [ ]
z = [ ]

for i in range(0, 10):
    x.append(i)
    y.append(i)
    z.append(i)
    
ax = plt.axes(projection='3d')
ax.scatter3D(x, y, z, c=z, cmap='Greens')
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章