python - 在 seaborn 热图中分隔组的线

标签 python matplotlib heatmap seaborn

我在 Python 中将数据绘制为 Seaborn 热图。我的数据本质上是按类别分组的,我希望在绘图上有线条来指示这些组在 map 上的位置。作为一个简单的例子,假设我想从文档中修改这个图......

import seaborn as sns; sns.set()
flights = sns.load_dataset("flights")
flights = flights.pivot("month", "year", "passengers")
ax = sns.heatmap(flights, cbar=False)

enter image description here

我想通过绘制如下图来强调一年中各季度之间的比较;我该怎么做?

enter image description here

最佳答案

你想要ax.hlines:

ax.hlines([3, 6, 9], *ax.get_xlim())

关于python - 在 seaborn 热图中分隔组的线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39352932/

相关文章:

python - 从数据存储加载数据集并合并到单个字典中。资源问题

python - py2exe 和 numpy 不相处

python - fig, ax = plt.subplots() 意思

python - 从图中删除颜色条

python - 基于行值的seaborn热图配色方案

python - 初学者 : Python Value error: invalid literal for int()

python - 查找并替换 POM 中两个单词之间的内容

python - 如何在 matplotlib 中移动刻度标签

Python Bokeh 变空热图

python - 在绘图中创建具有固定单元格宽度的分组热图