如何儲存 Matplotlib 3d 旋轉圖?
若要儲存 Matplotlib 3d 旋轉圖,我們可以採取以下步驟 −
- 設定 figure 大小,並調整子圖之間的填充和周圍的填充。
- 建立新的 figure 或啟用現有的 figure。
- 將'~.axes.Axes'新增到 figure 中,作為子圖排列的一部分。
- 返回一個元組 X, Y, Z,其中包含測試資料集。
- 繪製 3D 曲面。
- 以某個角度旋轉座標軸。
- 重新繪製當前 figure。
- 執行 GUI 事件迴圈幾秒鐘。
- 要顯示 figure,請使用 show() 方法。
示例
from mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111, projection='3d') X, Y, Z = axes3d.get_test_data(0.1) ax.plot_wireframe(X, Y, Z, rstride=5, cstride=5) for angle in range(0, 360): ax.view_init(30, angle) plt.draw() plt.pause(.001) plt.show()
輸出
廣告