我的数据都是整数,但是画密度图以后,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))

搞定

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐