2014-03-25 70 views
1

我在Python中颤抖函数挣扎。Matplotlib:颤抖二维数组

我想创建一个给定的二维数组的2D矢量字段,其中包含使用颤抖的向量的两个组件。

鉴于数组b:

>>> b 
VigraArray(shape=(512, 512, 2), axistags=x y c, dtype=float32, data= 
[[[ 0.59471679 0.51902866 0.38904327 ..., -0.56878477 -0.50834674 
-0.48382956] 
[ 0.58222073 0.50713873 0.37990916 ..., -0.56091702 -0.50057167 
-0.47613338] 
[ 0.53815156 0.46551338 0.34787226 ..., -0.54245669 -0.48314109 
-0.45911735] 
..., 

,并使用颤抖:

>>> X,Y = meshgrid(range(b.shape[0]),range(b.shape[1])) 
>>> quiver(X,Y,b[...,0],b[...,1]) 

回报:

Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2892, in quiver 
    ret = ax.quiver(*args, **kw) 
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 6641, in quiver 
    q = mquiver.Quiver(self, *args, **kw) 
File "/usr/lib/pymodules/python2.7/matplotlib/quiver.py", line 419, in __init__ 
self.set_UVC(U, V, C) 
File "/usr/lib/pymodules/python2.7/matplotlib/quiver.py", line 463, in set_UVC 
    U = ma.masked_invalid(U, copy=False).ravel() 
File "/usr/lib/python2.7/dist-packages/numpy/ma/core.py", line 3969, in ravel 
    r._mask = ndarray.ravel(self._mask).reshape(r.shape) 
File "/usr/lib/python2.7/dist-packages/vigra/arraytypes.py", line 1308, in reshape 
    res = numpy.ndarray.reshape(self, shape, order) 
TypeError: an integer is required 

我从来没有使用VigraArray与matplotlib的问题,所以我不认为这是问题。感谢帮助!

+0

你试过'b [:,0]'而不是'b [...,0]'? – Schorsch

+0

我试过'b [:,:,0]','b [:,0]'形状错了,但是同样的错误 – l4l1lu

回答

0

事实上,pylab.quiver似乎没有正确处理vigra.VigraArray。下面的替换为我工作:

b[...,0] = numpy.array(b[...,0]) 
b[...,1] = numpy.array(b[...,1])