python Matplotlib 控制x轴和y轴都为整数
python Matplotlib 控制x轴和y轴都为整数frommatplotlib.tickerimportMaxNLocatorplt.gca().xaxis.set_major_locator(MaxNLocator(integer=True))plt.gca().yaxis.set_major_locator(MaxNLocator(integer=True))搞定
·
我的数据都是整数,但是画密度图以后,x轴居然有小数,有的图里y轴有小数。搜了半天也没找到好点的解决方案,终于在google找到了。
办法如下:
from matplotlib.ticker import MaxNLocator
加上下边这两句就OK了
plt.gca().xaxis.set_major_locator(MaxNLocator(integer=True))
plt.gca().yaxis.set_major_locator(MaxNLocator(integer=True))
搞定
更多推荐
已为社区贡献1条内容
所有评论(0)