【问题标题】:seaborn heatmap conditional borderseaborn 热图条件边界
【发布时间】:2021-01-20 10:26:01
【问题描述】:

我有一个包含基因名称、倍数变化和 p 值的数据框。

我可以使用seaborn.heatmap 将折叠变化绘制为颜色渐变。

如何在 p 值

【问题讨论】:

  • 尝试分而治之 - 分别绘制每个单元格,如果需要 - 在其周围添加边框

标签: seaborn heatmap


【解决方案1】:

您的数据框是什么样子以及如何创建热图有点不清楚。

以下代码根据一些随机数据创建热图,并在某些单元格周围创建边框(以及可选的阴影线):

import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import numpy as np
import pandas as pd
import seaborn as sns

df = pd.DataFrame({'gene name': np.repeat(list('abcdefg'), 10),
                   'change ID': np.tile(np.arange(10), 7),
                   'fold change': np.random.rand(70),
                   'p-value': np.random.rand(70) * 0.5})
heatmap_data = pd.pivot_table(df, values='fold change', index=['gene name'], columns='change ID')

ax = sns.heatmap(heatmap_data, square=True)
for index, row in df[df['p-value'] < 0.05].iterrows():
    name_pos = heatmap_data.index.get_loc(row['gene name'])
    id_pos = heatmap_data.columns.get_loc(row['change ID'])
    ax.add_patch(Rectangle((id_pos, name_pos), 1, 1, ec='cyan', fc='none', lw=2, hatch='//'))
plt.show()

【讨论】:

  • 如果这回答了你的问题,你可以考虑投票和/或accepting答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-02
  • 2020-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-04
相关资源
最近更新 更多