2013-05-13 28 views
6

Tôi đang tạo đường bao cao độ nước ngầm với Matplotlib. Xem bên dướiThêm mũi tên lưu lượng nước vào Matplotlib Đường đồng mức

Đây là những gì tôi có bây giờ; làm thế nào tôi có thể thêm mũi tên dòng chảy nước như hình dưới đây? enter image description here

Tôi muốn thêm mũi tên để làm cho nó trông như thế này: Groundwater Contour with Arrows

Nếu ai có một số ý tưởng và/hoặc mẫu mã mà sẽ được đánh giá rất nhiều.

Trả lời

13

Bạn sẽ cần phiên bản matplotlib gần đây (> = 1.2), nhưng streamplot sẽ thực hiện việc này. Bạn chỉ cần lấy gradient âm của đầu (lưới nước "a.k.a." cho lưới mặt nước).

Như một ví dụ nhanh tạo ra từ những quan sát điểm ngẫu nhiên của người đứng đầu:

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() 

enter image description here

+0

phản ứng vui nhộn. Lần nữa. – pelson

+0

Cảm ơn! Tôi đánh giá cao nó! –

+0

Joe, cảm ơn bạn một lần nữa- Tôi đã có thể nhận được các streamplot làm việc với một caveat. Một số mũi tên xuất hiện để chỉ hướng sai. Bạn có nghĩ rằng bạn có thể xem? http://stackoverflow.com/questions/16897585/matplotlib-streamplot-arrows-pointing-the-wrong-way –

Các vấn đề liên quan