加水流量箭头Matplotlib轮廓图(Adding water flow arrows to Ma

2019-09-02 23:50发布

我生成与Matplotlib地下水海拔轮廓。 见下文

以下是我现在有; 我怎么能加水流量箭像下面的图片?

我想补充的箭头,使它看起来像这样:

如果任何人有一些想法和/或代码示例,将不胜感激。

Answer 1:

你需要一个最近(> = 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()



文章来源: Adding water flow arrows to Matplotlib Contour Plot