如何用我的imshow图设置xticks和yticks? [英] How to set xticks and yticks with my imshow plot?

查看:33
本文介绍了如何用我的imshow图设置xticks和yticks?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码

import numpy as np
import matplotlib.pyplot as plt

with open('nm.dat','r') as f:
    vst = map(float, f)

print vst    

a=np.asarray(vst)
print len(a)

a11=a.reshape(4,22)

plt.imshow(a11, cmap='hot', interpolation='nearest')
plt.colorbar()
plt.show()

我的图片

我希望我的x轴用等距的0,8,16,24,32,40,48,56,64,72,80,88个刻度标记.对于y轴0,2,4,6,8.怎么解决呢?

I would like my x axis to be marked with equidistant 0,8,16,24,32,40,48,56,64,72,80,88 ticks.For y axis 0,2,4,6,8. How to solve this?

推荐答案

您缺少imshow中的range参数.imshow假定像素与您的物理"单位之间存在线性关系.你可以使用:

You are missing the extent argument in imshow. imshow assumes that there is a linear relation between pixels and your "physical" unit. You could just use:

plt.imshow(a11, cmap='hot', interpolation='nearest', extent=[0,88,0,8], origin='lower')

范围变量必须给定,范围= [xmin,xmax,ymin,ymax].origin='lower' 参数是指定您的 [0,0] 坐标必须放置在轴的左下角.否则,它被放置在轴的左上角.

The extent variable has to be given such that extent=[xmin,xmax,ymin,ymax]. The origin='lower' argument is to specify that your [0,0] coordinate has to be placed in the bottom left of the axis. Otherwise, it is placed in the top left of the axis.

最后,为了仅显示某些特定的刻度,您可能需要使用:

Finally, for showing only some particular ticks, you may want to use:

ax = plt.gca()
xticks = [0,8,16,24,32,40,48,56,64,72,80,88]
yticks = [0,2,4,6,8]
ax.xaxis.set_xticks(xticks)
ax.xaxis.set_yticks(yticks)

这篇关于如何用我的imshow图设置xticks和yticks?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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