【发布时间】:2016-02-12 08:57:59
【问题描述】:
我有一个数据文件,分为 4 列,第一列和第二列用于 x 和 y 坐标,第三和第四列用于 x 和 y 位置处矢量场的 x 和 y 分量(同一行) . x 和 y 的间距相等。
我想用一个“颤动”图来可视化向量场,其中向量的范数用作地图来为向量着色。不知道是否可以降低网格上点的密度以更好地查看向量?
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import cm
from numpy import *
from pylab import *
x, y, fx, fy = np.genfromtxt(r'vecfield.dat', unpack=True)
norm = np.sqrt(fx**2+fy**2)
xx = linspace(min(x), max(x), num=150)
yy = linspace(min(y), max(y), num=10)
X, Y = mgrid(xx, yy)
q = plt.quiver(X, Y, fx, fy, norm, cmap=cm.jet, angles='xy', scale=1)
plt.axis()
plt.show()
提前感谢您的帮助。
这是我的约会示例:
0.00 0.00 0.000 0.000 0.000
0.00 0.50 -0.502 -0.008 0.503
0.00 1.00 -0.012 -0.005 3.836
0.00 1.50 -0.067 -0.005 5.080
0.00 2.00 0.085 -0.010 3.631
0.00 2.50 0.172 -0.006 5.079
0.00 3.00 0.191 0.001 4.646
0.00 3.50 0.290 -0.022 4.579
0.00 4.00 0.202 -0.006 4.993
0.00 4.50 0.096 0.010 4.836
0.00 5.00 0.623 -0.022 5.079
0.00 5.50 0.463 -0.002 4.422
0.00 6.00 -0.473 0.005 3.943
0.00 6.50 0.064 0.004 4.466
0.00 7.00 0.097 -0.008 5.203
0.00 7.50 -0.079 0.005 4.342
0.00 8.00 -0.369 0.009 4.491
0.00 8.50 -0.517 -0.043 5.564
0.00 9.00 -0.044 -0.054 5.036
0.00 9.50 -0.111 -0.037 5.482
0.00 10.00 0.358 -0.027 6.038
0.00 10.50 0.150 -0.037 5.570
0.00 11.00 0.091 -0.010 4.989
0.00 11.50 0.040 0.006 4.712
0.00 12.00 -0.737 -0.004 4.976
0.00 12.50 -0.661 -0.017 5.867
0.00 13.00 -0.047 -0.053 5.292
0.00 13.50 0.124 -0.095 4.988
0.00 14.00 -0.048 -0.146 5.646
0.00 14.50 0.271 -0.097 5.450
0.00 15.00 0.645 0.080 4.688
0.00 15.50 0.243 0.012 5.192
0.00 16.00 -0.245 0.007 4.699
0.00 16.50 0.437 -0.125 5.038
0.00 17.00 0.211 -0.282 6.002
0.00 17.50 0.175 -0.147 4.767
0.00 18.00 0.816 -0.177 2.794
0.00 18.50 0.131 -0.031 0.615
0.00 19.00 0.000 0.000 0.000
0.00 19.50 0.000 0.000 0.000
0.00 20.00 0.000 0.000 0.000
0.00 20.50 0.000 0.000 0.000
0.00 21.00 0.000 0.000 0.000
【问题讨论】:
-
据我了解,你不需要创建mesh grid,可以直接调用
plt.quiver(x, y, fx, fy, norm, cmap=cm.jet, angles='xy', scale=1)
标签: python vector multiple-columns