python如何画火山图
python中如何画火山图
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 result.loc[(result.x<-cut_off_logFC)&(result.y 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轴标签 以上就是python中画火山图的方法,希望能对大家有所帮助,更多Python学习教程请关注IT培训机构:千锋教育。

猜你喜欢LIKE
相关推荐HOT
更多>>
python函数中使用for循环
python函数中使用for循环1、在for循环中使用函数需要更长的执行时间,因为每次迭代都会调用该函数。2、如果for循环是在函数内部实现的,那么该...详情>>
2023-11-14 13:53:34
python3.1版本的特性有哪些
python3.1中的特性有哪些1、千位数格式化,可以在使用字符串格式化函数时直接完成。在格式化大数时,通常是每三位数放置逗号,使数字更易读(例...详情>>
2023-11-14 13:18:27
python__new__()和__init__()有什么区别?
在python中,__new__()不是一定要有,只有继承自object的类才有,该方法可以return父类(通过super(当前类名,cls).__new__())出来的实例,或者直...详情>>
2023-11-14 12:38:55
pythonwheel是什么
python的第一个主流打包格式是.egg文件,现在大家庭中又有了一个叫做Wheel(*.whl)的新成员。wheel“被设计成包含PEP376兼容安装(一种非常接近于...详情>>
2023-11-14 11:30:39热门推荐
技术干货






