2017-01-13 100 views
0

我在速度矢量(U,V)在不同位置(X,Y)有一個數據。我知道使用數據來繪製顫抖情節。將矩形添加到箭袋圖

plt.quiver(data[:,0],data[:,1],data[:,3],data[:,4]) 

在箭袋圖中,我需要顯示一個矩形區域。

我是python新手。

回答

0

matplotlib中的矩形可以使用matplotlib.patches.Rectangle((x, y), width, height, ...)來繪製。

例如,像這樣:

import matplotlib.pyplot as plt 
import matplotlib.patches as patches 
import numpy as np 

# generate some data 
data = np.random.rand(10,5) 
# define a rectangle 
# patches.Rectangle((x, y), width, height, ...) 
rectangle = patches.Rectangle((0.2, 0.3), 0.5, 0.4, alpha=0.5) 
ax = plt.gca() 
# add the rectangle to the axes 
ax.add_patch(rectangle) 
# plot the quiver plot 
plt.quiver(data[:,0],data[:,1],data[:,2]*5,data[:,3]*5, data[:,4]) 

plt.show() 

enter image description here