Python繪製三維圖形
- 2020 年 1 月 3 日
- 筆記
需要安裝numpy和matplotlib庫,我都是pip庫安裝,這樣比較簡單。
import numpy as np import matplotlib.pyplot as plt import mpl_toolkits.mplot3d x, y = np.mgrid[-2 : 2 : 20j, -2 : 2 : 20j] z = 50 * np.sin(x + y) # 測試數據 ax = plt.subplot(111, projection = '3d') # 三維圖形 ax.plot_surface(x, y, z, rstride = 2, cstride = 1, cmap = plt.cm.Blues_r) ax.set_xlabel('x') # 設置坐標軸標籤 ax.set_xlabel('y') ax.set_xlabel('z') plt.show()
這是最終效果

參考自《Python可以這樣學》414頁