首页IT科技python 火焰图(python中如何画火山图)

python 火焰图(python中如何画火山图)

时间2025-06-21 02:53:52分类IT科技浏览3968
导读:1、导入数据 importpandasaspd...

1            、导入数据

importpandasaspd#Dataanalysis importnumpyasnp#Scientificcomputing importseabornassns#Statisticalvisualization #读取数据 df=pd.read_csv(./dataset_volcano.txt,sep=\t) result=pd.DataFrame() result[x]=df[logFC] result[y]=df[P.Value] result[-log10(pvalue)]=-df[P.Value].apply(np.log10)

2                  、设置阈值

#设置pvalue和logFC的阈值 cut_off_pvalue=0.0000001 cut_off_logFC=1

3      、设置分组

#分组为up,normal,down result.loc[(result.x>cut_off_logFC)&(result.y<cut_off_pvalue),group]=up result.loc[(result.x<-cut_off_logFC)&(result.y<cut_off_pvalue),group]=down result.loc[(result.x>=-cut_off_logFC)&(result.x<=cut_off_logFC)|(result.y>=cut_off_pvalue),group]=normal

4         、绘制散点图

#绘制散点图 ax=sns.scatterplot(x="x",y="-log10(pvalue)", hue=group, hue_order=(down,normal,up), palette=("#377EB8","grey","#E41A1C"), alpha=0.5, s=15,

5                  、设置散点图

#确定坐标轴显示范围 xmin=-6 xmax=10 ymin=7 ymax=13 ax.spines[right].set_visible(False)#去掉右边框 ax.spines[top].set_visible(False)#去掉上边框 ax.vlines(-cut_off_logFC,ymin,ymax,color=dimgrey,linestyle=dashed,linewidth=1)#画竖直线 ax.vlines(cut_off_logFC,ymin,ymax,color=dimgrey,linestyle=dashed,linewidth=1)#画竖直线 ax.hlines(-np.log10(cut_off_pvalue),xmin,xmax,color=dimgrey,linestyle=dashed,linewidth=1)#画竖水平线 ax.set_xticks(range(xmin,xmax,4))#设置x轴刻度 ax.set_yticks(range(ymin,ymax,2))#设置y轴刻度 ax.set_ylabel(-log10(pvalue),fontweight=bold)#设置y轴标签 ax.set_xlabel(log2(foldchange),fontweight=bold)#设置x轴标签

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
网站建设的核心内容及详细介绍(深入了解网站建设的基本概念和核心技术)