我生成了一个热图 , 该热图在右下角的单元格中缺少值(白色,但是与其他淡紫色的单元格没有明显区别)。 我想使用特定的颜色或图案来突出显示此单元格,并提到这种颜色/图案与颜色栏或图例中某处的缺失值相关联。 我不想使用补丁程序,因为我正在使用类似的代码生成具有许多缺失值的热图。
请在下面找到我的代码。 谢谢你的帮助!
#picking colors and ticks bounds for the colorbar:
cmap = colors.ListedColormap(["black",'indigo','navy','b','cornflowerblue', 'lightskyblue','lavender'])
bounds=[0, 3, 5, 8, 12, 15, 20,30]
norm = colors.BoundaryNorm(bounds, cmap.N)
#creating the heat map for precipitation profile:
fig, ax = plt.subplots(figsize=(15,8))
heatmap=plt.pcolor(ym_dry, cmap=cmap, norm=norm, edgecolor='white')
ax.set_xlabel("Months", fontsize=20)
ax.set_ylabel("Years", fontsize=20)
ax.set_title("Monthly total of dry days", fontsize=24)
plt.xticks(np.arange(0.5, 12.5, 1))
ax.set_xticklabels(dim, rotation=45, ha='center', minor=False)
ax.set_yticks(np.arange(0.5,24.5,1))
ax.set_yticklabels(dim2)
ax.grid(False)
ax.add_patch(Rectangle((-0.5, 15), 12.5, 5, fill=True, lw=3, alpha=0.8, color = "grey"))
cbar = fig.colorbar(heatmap, norm=norm, cmap = cmap, ticks=[0, 3, 5, 8, 10, 12, 15, 20, 25, 30], boundaries=bounds, spacing='proportional')
fig.text(0.84, 0.5, "Monthly total of dry days", fontsize=18, va="center",
ha="center", rotation=-90)
ax.tick_params(labelsize=16)
cbar.ax.tick_params(labelsize=15)
fig.show()