使用imshow校正轴 [英] correcting the axes using imshow

查看:73
本文介绍了使用imshow校正轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用numpy.meshgrid和pylab.imshow()绘制轮廓图.首先使用我在stackoverflow上发现的一些技巧,这确实非常有效(谢谢伙计!:D)

I was trying to make a contour plot using numpy.meshgrid and pylab.imshow(); this worked really well at first using some tips I found on stackoverflow (thanks guy! :D )

f = scipy.linspace(1e5,1e6,100)
A = scipy.linspace(1e3,1e5,100)
ff,AA = numpy.meshgrid(f,A)
SLP = calc_SLP2D(ff,AA)
maxAmps = maxA(f)
print maxAmps
brezovich = calc_SLP2D(f,maxAmps)
print brezovich
pylab.imshow(SLP,origin='lower')
pylab.plot(f,maxA(f))
pylab.colorbar()
pylab.xlabel('Frequency [kHz]',{'fontsize':20})
pylab.ylabel('Field Amplitude [A/m]',{'fontsize':20})
pylab.title('Brezovich Criterion',{'fontsize':20})
pylab.grid()
pylab.show()

轴错误的轮廓图片http://web.mit.edu/scottnla/Public/SLP_contour.pdf

但是,您会注意到,轴是根据两个输入矩阵的大小而不是实际值进行编号的.横坐标应从100,000到1,000,000,纵坐标应从1000到5000.我在stackoverflow上读到,解决方案是使用'extent'选项,如下所示:

However, you'll notice that the axes are numbered by the size of the two input matrices and not by the actual values. The abscissa should go from 100,000 to 1,000,000 with the ordinate going from 1000 to 5000. I read on stackoverflow that the solution is to use the 'extent' option as so:

pylab.imshow(SLP,origin='lower',extent=(ff.min(),ff.max(),AA.min(),AA.max()))

这确实可以固定轴,但是缩放图像是一种很奇怪的方法:

This does fix the axes, but scales the image is a really weird way:

具有正确轴但图形不正确的轮廓图http://web.mit.edu /scottnla/Public/SLP_contour2.pdf

我不确定是什么原因造成的.

And I'm not sure what causes this.

关于如何在不使图像看起来如此奇怪的情况下重新缩放轴的任何想法?

Any thoughts on how I can rescale the axes without making the image look so odd?

谢谢!

内森·拉琴梅尔

推荐答案

尝试将参数aspect='auto'添加到imshow.像这样:

Try to add the parameter aspect='auto' to imshow. Like this:

pylab.imshow(SLP,aspect='auto',origin='lower',extent=(ff.min(),ff.max(),AA.min(),AA.max()))

这篇关于使用imshow校正轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆