在 Python Matplotlib 中繪製軸上向量場?
如需在 matplotlib 中繪製軸上向量場,我們可以按以下步驟進行 −
設定影像大小和調整子圖之間和周圍的空白。
使用 numpy 建立 X,Y,T,R,U 和 V 資料點。
新增一個到當前影像的軸並使其成為當前軸。
使用 quiver() 方法繪製三維箭頭場。
使用 show() 方法顯示影像。
示例
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True n = 8 X, Y = np.mgrid[0:n, 0:n] T = np.arctan2(Y - n / 2., X - n/2.) R = 10 + np.sqrt((Y - n / 2.0) ** 2 + (X - n / 2.0) ** 2) U, V = R * np.cos(T), R * np.sin(T) plt.axes([0.025, 0.025, 0.95, 0.95]) plt.quiver(X, Y, U, V, R, cmap="copper") plt.show()
輸出
廣告