gpt4 book ai didi

python - 向 matplotlib/seaborn 图中的某些单元格添加自定义边框

转载 作者:太空狗 更新时间:2023-10-29 17:59:23 26 4
gpt4 key购买 nike

现在我正在使用 Seaborn 的 clustermap 生成一些集群热图 - 到目前为止还不错。

对于特定用例,我需要在特定单元格周围绘制彩色边框。有没有办法做到这一点?或者使用 matplotlib 中的 pcolormesh,或者任何其他方式?

最佳答案

你可以通过重绘 Rectangle patch 来做到这一点在您要突出显示的单元格上。使用 seaborn docs 中的示例图

import seaborn as sns
import matplotlib.pyplot as plt
sns.set()
flights = sns.load_dataset("flights")
flights = flights.pivot("month", "year", "passengers")
g = sns.clustermap(flights)

我们可以通过做高亮一个单元格

from matplotlib.patches import Rectangle
ax = g.ax_heatmap

ax.add_patch(Rectangle((3, 4), 1, 1, fill=False, edgecolor='blue', lw=3))
plt.show()

这将生成带有突出显示单元格的绘图,如下所示:

enter image description here

请注意,单元格的索引是基于左下角原点的 0。

关于python - 向 matplotlib/seaborn 图中的某些单元格添加自定义边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31290778/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com