Adjusting gridlines and ticks in matplotlib imshow

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

    You can shift the pixels by passing the extent argument to imshow. extent is a 4-element list of scalars (left, right, bottom, top):

    foo = np.random.rand(35).reshape(5, 7)
    # This keeps the default orientation (origin at top left):
    extent = (0, foo.shape[1], foo.shape[0], 0)
    _, ax = plt.subplots()
    ax.imshow(foo, extent=extent)
    ax.grid(color='w', linewidth=2)
    ax.set_frame_on(False)
    

提交回复
热议问题