Adjusting gridlines and ticks in matplotlib imshow

前端 未结 4 1116
遇见更好的自我
遇见更好的自我 2021-02-01 15:07

I\'m trying to plot a matrix of values and would like to add gridlines to make the boundary between values clearer. Unfortunately, imshow decided to locate the tick marks in the

4条回答
  •  [愿得一人]
    2021-02-01 15:37

    Try to shift axes ticks:

    ax = plt.gca()
    ax.set_xticks(np.arange(-.5, 10, 1))
    ax.set_yticks(np.arange(-.5, 10, 1))
    ax.set_xticklabels(np.arange(1, 12, 1))
    ax.set_yticklabels(np.arange(1, 12, 1))
    

提交回复
热议问题