问题描述
我一直在使用以下代码:
loc = plticker.MultipleLocator(base=1)
ax.yaxis.set_minor_locator(loc)
ax.yaxis.set_major_locator(plticker.MaxNLocator(integer=True))
ax.grid(axis='y',which='both')
非常成功地获得每个单位都带有刻度的图形:
,但是相同的代码不适用于此数据集并生成此图,该图将忽略这两个条件:
如何避免这种情况?
谢谢
解决方法
ax.yaxis.set_major_locator(plticker.MultipleLocator(base=1.0))
如果单位只是每个整数,则可以尝试用MultipleLocator(base = 1.0)替换MaxNLocatior,如上面的代码所示。不确定为什么您当前的代码不起作用。