Rescaling axis in Matplotlib imshow under unique f

2020-07-10 09:36发布

问题:

I have written a function module that takes the argument of two variables. To plot, I had

x, y = pylab.ogrid[0.3:0.9:0.1, 0.:3.5:.5]
z = np.zeros(shape=(np.shape(x)[0], np.shape(y)[1]))

for i in range(len(x)):
    for j in range(len(y[0])):    
        z[i][j] = fancyFunction(x[i][0], y[0][j])

pylab.imshow(z, interpolation="gaussian")

The image I get is the following:

But when I tried rescaling the x and y axis to match the ranges of [0.3:0.9:0.1, 0.:3.5:.5] thru pylab.imshow(z, interpolation="gaussian", extent=[.3,.9,0.,3.5]) I get

I've been googling for hours but still couldn't find a way to make a square plot with differently scaled axis.

Thanks!

回答1:

Use the aspect argument:

pylab.imshow(z, interpolation="gaussian", extent = [.3,.9,0.,3.5], aspect='auto')