在 IPython 或 Jupyter Notebook 中顯示可旋轉 3D 繪圖
透過在軸上建立 3D 投影並使用 view_init() 迭代該軸以獲取不同角度,我們可以旋轉輸出圖表。
步驟
建立新圖形或啟用現有圖形。
將 `~.axes.Axes` 新增到圖形,作為 nrow = 1、ncols = 1、index = 1 和 projection = '3d' 子圖排列的一部分。
使用方法 get_test_data 返回帶有測試資料集的元組 X、Y 和 Z。
使用資料測試資料 x、y 和 z 繪製 3D 線框。
為了使其可旋轉,我們可以使用 view_init() 方法以度(而不是弧度)設定軸的高度和方位。
若要顯示圖形,請使用 plt.show() 方法。
示例
from mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot as plt 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) # rotate the axes and update for angle in range(0, 360): ax.view_init(30, angle) plt.show()
輸出
廣告