I need to plot an array. I tried the code from Joe Kington (Show the values in the grid using matplotlib), but I get the error:
for (i, j), z in np.ndenumerate(array):
#ValueError: too many values to unpack (expected 2).
Can someone please help me find the mistake?
This is the code I tried:
with rasterio.open("C:/Users/...raster.tif") as data:
array = data.read()
fig, ax = plt.subplots()
ax.matshow(array, cmap='Greens')
ax.axis('off')
for (i, j), z in np.ndenumerate(array):
ax.text(j, i, '{:0.1f}'.format(z), ha='center', va='center')
fig = plt.gcf()
plt.savefig("C:/Users/...grid.jpeg")
plt.close(fig)