Can anyone help me understand this: the code below produces a plot in which the x and y axis labels are reversed relative to the direction in which z varies on the plot, although the gradient arrows are correctly oriented. Is there something I've missed in understanding the sense of the x and y directions in mgrid, imshow, and gradient?

"""

x,y axes seem to be reversed

"""

import numpy as np

from matplotlib.pylab import *

dx = .25; dy = .25

xlen = 2.0; ylen = 2.0

x,y = np.mgrid[-xlen:xlen:dx, -ylen:ylen:dy] #also works with ogrid

z = x

hold(True)

imshow(z, origin='lower', extent=[-xlen,xlen,-ylen,ylen])

colorbar()

[u,v] = np.gradient(z)

u /= dx; v /= dy

QP = quiver(x,y,u,v,pivot='middle',color=[0.5,0.5,0.5])

quiverkey(QP, 0.85, 1.05, 1.0, '1 unit', labelpos='N')

xlabel('x')

ylabel('y')

title('slope')

show()