如何在 Matplotlib 中使用 Axes3D 進行縮放?
要使用 Axes3D 進行縮放,我們可以採取以下步驟 -
- 設定圖形大小並調整子圖之間和周圍的邊距。
- 使用 figure() 方法建立一個新圖形或啟用一個現有圖形。
- 使用 Axes3D(fig) 方法獲取 3D 軸物件。
- 使用 scatter() 方法繪製 x、y 和 z 資料點。
- 若要顯示該圖形,請使用 show() 方法。
示例
from mpl_toolkits.mplot3d import Axes3D from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = Axes3D(fig) x = [2, 4, 6, 3, 1] y = [1, 6, 8, 1, 3] z = [3, 4, 10, 3, 1] ax.scatter3D(x, y, z, c=z, alpha=1, marker='d', s=150) plt.show()
輸出
廣告