Seaborn Complex Heatmap ---在瓦片内绘制圆圈来表示复杂的注释 [英] Seaborn Complex Heatmap---drawing circles within tiles to denote complex annotation

查看:29
本文介绍了Seaborn Complex Heatmap ---在瓦片内绘制圆圈来表示复杂的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 python 中有两个数据框.

I have two data-frames in python.

data_A
Name  X  Y
A     1  0
B     1  1
C     0  0

data_B
Name  X  Y
A     0  1
B     1  1
C     0  1

我想重叠这些热图,如果它在 data_frame A 中为 1,则图块为紫色(或任何颜色),但如果在 data_frame B 中为 1,则绘制一个圆圈(最好是第一).

I would like to overlap these heatmaps, where if it is a 1 in data_frame A, then the tile is colored purple (or any color), but if it's a 1 in data_frame B, then a circle is drawn (preferably the first one).

例如,热图将显示 A[,X][1] 紫色,但那些在两个数据框中都为 1 的将是带有点的紫色.C[,Y][3] 只有一个点,而 C[,X][3] 什么都没有.

So for example, the heatmap would show A[,X][1] colored purple, but those with 1 in both data frames would be purple with a dot. C[,Y][3] would have just a dot, while C[,X][3] would have nothing.

我似乎可以用 seaborn 进行遮罩,并用不同的颜色绘制两个热图,但颜色差异不够清晰,用户只能看到一个磁贴只有一个而不是两个.我认为在一个矩阵中用圆圈表示正数会更好.

I can seem to mask, with seaborn, and plot two heatmaps with different colors, but the color differential isn't clear enough that a user can simply see that a tile has only one versus both. I think having a circle to denote a positive in one matrix would be better.

有人知道如何使用 seaborn 将圆圈绘制到热图上吗?

Does anyone have an idea of how to plot circles onto a heatmap using seaborn?

推荐答案

要显示热图,您可以使用 imshow 图.要显示一些点,您可以使用 scatter 图.然后在相同的轴上绘制两者.

To show a heatmap you may use an imshow plot. To show some dots, you may use a scatter plot. Then just plot both in the same axes.

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

dfA = pd.DataFrame([[1,0],[1,1],[0,0]], columns=list("XY"), index=list("ABC"))
dfB = pd.DataFrame([[0,1],[1,1],[0,1]], columns=list("XY"), index=list("ABC"))

assert dfA.shape == dfB.shape

x = np.arange(0,len(dfA.columns))
y = np.arange(0,len(dfB.index))
X,Y=np.meshgrid(x,y)

fig, ax = plt.subplots(figsize=(2.6,3))
ax.invert_yaxis()
ax.imshow(dfA.values, aspect="auto", cmap="Purples")

cond = dfB.values == 1
ax.scatter(X[cond], Y[cond], c="crimson", s=100)

ax.set_xticks(x)
ax.set_yticks(y)
ax.set_xticklabels(dfA.columns)
ax.set_yticklabels(dfA.index)
plt.show()

使用点在同一热图上显示多个数据集的替代方法也可以

Alternatives to using a dot to show several datasets on the same heatmap could also

这篇关于Seaborn Complex Heatmap ---在瓦片内绘制圆圈来表示复杂的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆