Adjusting gridlines and ticks in matplotlib imshow

前端 未结 4 1193
遇见更好的自我
遇见更好的自我 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:27

    One can find it easier to use plt.pcolor or plt.pcolormesh:

    data = np.random.rand(10, 10)
    plt.pcolormesh(data, edgecolors='k', linewidth=2)
    ax = plt.gca()
    ax.set_aspect('equal')
    

    Though, there are some differences among them and plt.imshow, the most obvious being that the image is swapped by the Y-axis (you can reversed it back easily by adding ax.invert_yaxis() though). For further discussion see here: When to use imshow over pcolormesh?

提交回复
热议问题