2

I am trying to apply an affine transform to a quiver plot. This is an example based on one of the matplotlib quiver demos. Currently the result of the plot command transforms one direction while the result of the quiver command goes the other direction. Why is this and how do I fix it?

import matplotlib as mpl
from pylab import *
from numpy import ma

X,Y = meshgrid( arange(0,2*pi,.2),arange(0,2*pi,.2) )
U = cos(X)
V = sin(Y)

#3
fig = figure()
ax = subplot(111)
base_trans = ax.transData
tr =  mpl.transforms.Affine2D(matrix = array([[1,1,0],[0,1,0],[0,0,1]])) + base_trans

Q = quiver( X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3],
            pivot='mid', color='r', units='inches', transform = tr )
qk = quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', fontproperties={'weight': 'bold'})
plot( X[::3, ::3], Y[::3, ::3], 'k.', transform = tr)

axis([-1, 7, -1, 7])
fig.savefig('demo.png')
show()
4

0 回答 0