Seaborn热图Y刻度标签堆积

时间:2018-08-06 21:45:49

标签: python heatmap seaborn

我正在处理生物学数据,并且正在使用Seaborn的热图绘制Pearson R值,以便可以直观地比较22种细胞类型与其他每种细胞类型的表达(制作22x22热图)。

我有两个不同的问题。这是前几天我的情节:

You can see that in one plot the y-tick labels are spaced, but the last label is clipped off. Then in the other plot, all of the y-tick labels are present, but are spaced too tightly.

这就是我今天的情节。我非常不确定要解决第一幅图像中的问题时做出了什么更改(除了更改vmin和vmax以及配色方案),但是现在y-tick标签彼此重叠。

The y-ticks are all on top of each other.

这是我生成热图的代码:

def cancerHeatmap(patients, cancer):
    x_labels = ['Naive B','Memory B','Plasma','CD8 T','CD4 T Naive','CD4 T MR',
            'CD4 T MA','FH T','Tregs','GD T',
            'NK resting','NK activated','Monos','Macros M0','Macros M1','Macros M2',
            'Dendritic resting','Dendritic activated','Mast resting','Mast activated','Eosinophils','Neutrophils']
    pearsonrs = getPearsons(patients, cancer)
    axs = sns.heatmap(pearsonrs, cmap = 'RdYlBu', vmin=-0.6, vmax=0.6)
    axs.set_yticklabels(x_labels, rotation = 0, fontsize = 10)
    axs.set_xticklabels(x_labels, rotation = 90)
    axs.xaxis.set_ticks_position('top') 
    axs.set_xlabel(cancer)
    return axs

sns.set_style("whitegrid")
sns.despine()
plt.figure(figsize=(12,70))
plt.suptitle('Subtitle')
for i, cancer in enumerate(cancer_types):
    print cancer
    plt.subplot((len(cancer_types)/2)+1,2, i+1)
    ax = cancerHeatmap(patients, cancer)
    plt.tight_layout(rect=[0, 0, 1, 0.97])
    plt.savefig('outfile.pdf', dpi=200)

重要的细节是:

“ pearsonrs”是一个函数,可直接将所有值都生成numpy数组,直接进入热图

“ cancer_types”是我将为其生成热图的不同癌症类型的列表

我不知道为什么会这样,尤其是因为我可以使用此代码一次生成一个图,并且轴是完美的:

x_labels = ['Naive B','Memory B','Plasma','CD8 T','CD4 T Naive','CD4 T MR',
            'CD4 T MA','FH T','Tregs','GD T',
            'NK resting','NK activated','Monos','Macros M0','Macros M1','Macros 
            M2', 'Dendritic resting','Dendritic activated','Mast resting','Mast activated','Eosinophils','Neutrophils']
axs = sns.heatmap(np.array(pearsonrs), cmap = 'rainbow', vmin=-0.6, vmax=0.6)
axs.invert_yaxis()
axs.set_yticklabels(x_labels, rotation = 0, fontsize = 10)
axs.set_xticklabels(x_labels, rotation = 90, fontsize = 10)
axs.set_xlabel('Cancer')
axs.xaxis.set_ticks_position('top')

非常感谢您的帮助。

编辑: 我在rMBP和同事的rMBP上运行了相同的脚本,我的图形产生了带有堆叠轴标记的图形(图像2),而同事的计算机生成了具有奇数间距的图形(图像1)。

编辑2: 事实证明,每台计算机上的Conda安装都略有不同。将两台计算机都更新到最新的Conda(4.5.9)不会更改任何一台计算机产生的热图。

0 个答案:

没有答案
相关问题