天天看點

python Matplotlib 控制x軸和y軸都為整數

我的資料都是整數,但是畫密度圖以後,x軸居然有小數,有的圖裡y軸有小數。搜了半天也沒找到好點的解決方案,終于在google找到了。

python Matplotlib 控制x軸和y軸都為整數

辦法如下:

from matplotlib.ticker import MaxNLocator

 加上下邊這兩句就OK了

plt.gca().xaxis.set_major_locator(MaxNLocator(integer=True))

plt.gca().yaxis.set_major_locator(MaxNLocator(integer=True))

搞定