Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rescaling axis in Matplotlib imshow under unique function call

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: enter image description here

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

enter image description here

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

Thanks!

like image 393
neither-nor Avatar asked Aug 01 '12 18:08

neither-nor


People also ask

How do you normalize Imshow?

Just specify vmin=0, vmax=1 . By default, imshow normalizes the data to its min and max. You can control this with either the vmin and vmax arguments or with the norm argument (if you want a non-linear scaling).

What is interpolation in Imshow?

This example displays the difference between interpolation methods for imshow . If interpolation is None, it defaults to the rcParams["image. interpolation"] (default: 'antialiased' ). If the interpolation is 'none' , then no interpolation is performed for the Agg, ps and pdf backends.


1 Answers

Use the aspect argument:

pylab.imshow(z, interpolation="gaussian", extent = [.3,.9,0.,3.5], aspect='auto')
like image 87
jmetz Avatar answered Oct 13 '22 19:10

jmetz