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
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?