# Add a colorbar with commune names
cbar = plt.colorbar(mesh, ax=ax, ticks=np.arange(1, len(commune_names) + 1))
# Set the tick labels to the commune names
cbar.set_ticklabels(commune_names)
感谢您的帮助。
I确实找到了使用虚拟案例(和AI)的解决方案,请参见下面的示例,其中五个点(网格单元)用PcoLormesh绘制。 我错过了以下内容:
from matplotlib.colors import ListedColormap, BoundaryNorm
...
bounds = np.arange(0.5, 6.5, 1) # Boundaries between colors
norm = BoundaryNorm(bounds, cmap.N)
...
c = ax.pcolormesh(lon, lat, data, cmap=cmap, norm=norm, shading='auto')
对于定义界限和规范是必要的。