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培訓機構:千鋒教育。