Seaborn Complex Heatmap-在图块中绘制圆圈以表示复杂注释 [英] Seaborn Complex Heatmap---drawing circles within tiles to denote complex annotation

查看:584
本文介绍了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

  • Plotting two distance matrices together on same plot?
  • something like plt.matshow but with triangles

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

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