【发布时间】:2021-10-25 06:35:02
【问题描述】:
我需要绘制一个数组。我尝试了 Joe Kington (Show the values in the grid using matplotlib) 的代码,但我得到了错误:
for (i, j), z in np.ndenumerate(array):
#ValueError: too many values to unpack (expected 2).
有人可以帮我找出错误吗?
这是我试过的代码:
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)
【问题讨论】:
标签: python