[英]Adding water flow arrows to Matplotlib Contour Plot
I am generating a groundwater elevation contour with Matplotlib. 我用Matplotlib生成地下水高程轮廓。 See below
见下文
Here is what I have now; 这就是我现在拥有的; how can I add water flow arrows like the image below?
如何添加水流箭头,如下图所示?
I want to add arrows to make it look like this: 我想添加箭头使它看起来像这样:
If anyone has some ideas and/or code samples that would be greatly appreciated. 如果有人有一些想法和/或代码样本将非常感激。
You'll need a recent (>= 1.2) version of matplotlib, but streamplot
does this. 你需要一个最新的(> = 1.2)版本的matplotlib,但是
streamplot
。 You just need to take the negative gradient of your head (aka "water table" for surface aquifers) grid. 你只需要采取负头梯度(也就是表面含水层的“水位”)网格。
As a quick example generated from random point observations of head: 作为从头部的随机点观察产生的快速示例:
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.