如何将轴刻度设置为python上的主要刻度

时间:2012-07-30 20:13:06

标签: python matplotlib contour

enter image description here我正在使用等值线图生成一个值表(我对案例之间的偏差而不是实际值感兴趣)。 Z轴是常规的2d值数组。然而,X和Y轴是2d向量,我使用这个公式将其转换为数字:

v = (x,y)
val = x*5 + y + 2

其中0<=x<=2-2<=y<=2

我希望轴包含所有向量对,因此我创建了一个数组(xlabels),如下所示:

xlabel=[[0,-2], [0,-1], ..., [0,2], ... , [2,1], 2,2]]

当我尝试将其应用于我的情节时,我只得到第一组设置主要刻度标签的值。我使用的是:

ax1.set_xticklabels(xlabels)

和我得到的结果(顶部的xaxis):

如何将xaxis标签设置为全部?

1 个答案:

答案 0 :(得分:0)

解决方案是使用定位器:

from matplotlib.ticker import MultipleLocator
locator = MultipleLocator(1)
ax1.xaxis.set_major_locator(locator)
ax1.set_xticklabels(xlabels)
相关问题