Rescaling axis in Matplotlib imshow under unique function call

我怕爱的太早我们不能终老 提交于 2019-12-05 22:55:54

问题


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')


来源:https://stackoverflow.com/questions/11765025/rescaling-axis-in-matplotlib-imshow-under-unique-function-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!