[英]Adding water flow arrows to Matplotlib Contour Plot
我用Matplotlib生成地下水高程輪廓。 見下文
這就是我現在擁有的; 如何添加水流箭頭,如下圖所示?
我想添加箭頭使它看起來像這樣:
如果有人有一些想法和/或代碼樣本將非常感激。
你需要一個最新的(> = 1.2)版本的matplotlib,但是streamplot
。 你只需要采取負頭梯度(也就是表面含水層的“水位”)網格。
作為從頭部的隨機點觀察產生的快速示例:
import numpy as np
from scipy.interpolate import Rbf
import matplotlib.pyplot as plt
# Make data repeatable
np.random.seed(1981)
# Generate some random wells with random head (water table) observations
x, y, z = np.random.random((3, 10))
# Interpolate these onto a regular grid
xi, yi = np.mgrid[0:1:100j, 0:1:100j]
func = Rbf(x, y, z, function='linear')
zi = func(xi, yi)
# -- Plot --------------------------
fig, ax = plt.subplots()
# Plot flowlines
dy, dx = np.gradient(-zi.T) # Flow goes down gradient (thus -zi)
ax.streamplot(xi[:,0], yi[0,:], dx, dy, color='0.8', density=2)
# Contour gridded head observations
contours = ax.contour(xi, yi, zi, linewidths=2)
ax.clabel(contours)
# Plot well locations
ax.plot(x, y, 'ko')
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.