使用 Pandas Dataframe 注释 seaborn clustermap
Annotate seaborn clustermap with Pandas Dataframe
我正在使用 seaborn (v.0.7.0) 绘制热图。这是我的代码:
Updated code after fixing the problem
### Get Data
sns.set(style="white")
adata = pd.read_csv("Test.txt", sep="\t",index_col=0)
adata_log = np.log2(adata)
e = adata.iloc[0:7,0:3]
e_log = adata_log.iloc[0:7,0:3]
#### Set up the matplotlib figure
f, ax = plt.subplots(figsize=(11, 9))
#### Set color
hmcol = ["#ffffff","#ffffff","#fbe576","#c06e36","#9a2651"]
cmap = sns.blend_palette(hmcol,as_cmap=True)
#### Plot clustermap
sns.set(font_scale=0.8) ## 0.8 for normal use
aplot = sns.clustermap(e_log,cmap=cmap,method='average', metric='euclidean',standard_scale=None,row_cluster=False,col_cluster=False,row_linkage=None,col_linkage=None,linewidths=.05,square=True,annot=e,annot_kws={"size": 15},fmt='.2f')
aplot.cax.set_visible(False) #remove color bar
plt.setp(aplot.ax_heatmap.xaxis.get_majorticklabels(), rotation=90) ## Y-Axis label rotations
plt.setp(aplot.ax_heatmap.yaxis.get_majorticklabels(), rotation=0) ## X-Axis label rotations
##Save Figure
aplot.savefig(“Test-Fig1.0.pdf",orientation='potrait',dpi=600)
有什么方法可以将数据框“e”中的值用作注释?我试过了
annot=e
在 clustermap 中,但它给我一个错误:
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty,
a.bool(), a.item(), a.any() or a.all().
还有,反正我画的是横屏模式?这是上面代码中的数据和图形:
print(e)
X Y Z
A 100.72 90.20 13.58
B 160.98 162.24 12.85
C 6.76 8.03 0.66
D 241.49 277.89 29.43
E 156.78 145.54 30.72
F 6.09 5.96 0.93
G 4.57 1.16 0.74
升级'seaborn'到v0.7.1解决了注释问题。我已经用修复更新了我的答案。
对于横向绘图,我想最简单的方法是将我的数据从高顺序更改为长顺序,即通过复制数据并按转置粘贴来更改输入测试文件文件。
巴德
我正在使用 seaborn (v.0.7.0) 绘制热图。这是我的代码:
Updated code after fixing the problem
### Get Data
sns.set(style="white")
adata = pd.read_csv("Test.txt", sep="\t",index_col=0)
adata_log = np.log2(adata)
e = adata.iloc[0:7,0:3]
e_log = adata_log.iloc[0:7,0:3]
#### Set up the matplotlib figure
f, ax = plt.subplots(figsize=(11, 9))
#### Set color
hmcol = ["#ffffff","#ffffff","#fbe576","#c06e36","#9a2651"]
cmap = sns.blend_palette(hmcol,as_cmap=True)
#### Plot clustermap
sns.set(font_scale=0.8) ## 0.8 for normal use
aplot = sns.clustermap(e_log,cmap=cmap,method='average', metric='euclidean',standard_scale=None,row_cluster=False,col_cluster=False,row_linkage=None,col_linkage=None,linewidths=.05,square=True,annot=e,annot_kws={"size": 15},fmt='.2f')
aplot.cax.set_visible(False) #remove color bar
plt.setp(aplot.ax_heatmap.xaxis.get_majorticklabels(), rotation=90) ## Y-Axis label rotations
plt.setp(aplot.ax_heatmap.yaxis.get_majorticklabels(), rotation=0) ## X-Axis label rotations
##Save Figure
aplot.savefig(“Test-Fig1.0.pdf",orientation='potrait',dpi=600)
有什么方法可以将数据框“e”中的值用作注释?我试过了
annot=e
在 clustermap 中,但它给我一个错误:
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
还有,反正我画的是横屏模式?这是上面代码中的数据和图形:
print(e)
X Y Z
A 100.72 90.20 13.58
B 160.98 162.24 12.85
C 6.76 8.03 0.66
D 241.49 277.89 29.43
E 156.78 145.54 30.72
F 6.09 5.96 0.93
G 4.57 1.16 0.74
升级'seaborn'到v0.7.1解决了注释问题。我已经用修复更新了我的答案。
对于横向绘图,我想最简单的方法是将我的数据从高顺序更改为长顺序,即通过复制数据并按转置粘贴来更改输入测试文件文件。
巴德