[英]Obtaining the coordinates of streamlines in python
我正在嘗試在存在磁場(由永磁體產生)的情況下對等離子體進行數值計算。 我使用 streamplot 命令從數據中繪制了磁場:
現在,我想沿着場線手動創建一個網格,我需要用於繪制它們的點的坐標。 這對我很重要,因為等離子體將沿着或穿過場線流動,我希望代碼開發變得更容易。
我試圖分析 streamplot 命令的輸出,但無法獲得坐標。
stream = ax.streamplot(Z, R, B_Z, B_R, color=color, linewidth=1,
cmap=plt.cm.inferno,density=2.5, arrowstyle='->', arrowsize=1)
我知道我可以通過對場數據進行數值積分來找到流函數,然后用它來繪制和存儲流線的坐標,但這會很麻煩。
請指導我尋找任何更簡單的選擇。
您可以通過調用.get_paths()
或.get_segments()
來獲取流線段。
stream = ax.streamplot(...)
paths = strm.lines.get_paths()
segments = strm.lines.get_segments()
但是,這些是線條的單個段,通常不清楚哪個段屬於屏幕上看到的哪條線。
由於您似乎需要數據進行定量分析,我建議不要依賴流圖本身(旨在提供良好的視覺表示),而是根據您的數據計算數量。
在@ImportanceOfBeingErnest 之后,我能夠通過
density = 100 # defaults to 30- increased for more precision in the streamline
starting_point = np.array([[-180, -1980]])
strm = plt.streamplot(X, Y, U, V, density=density, start_points=starting_point)
num_pts = len(strm.lines.get_segments())
flow_line = np.full((num_pts, 2), np.nan)
for i in range(num_pts):
flow_line[i,:] = strm.lines.get_segments()[i][0,:]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.