新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python中如何畫火山圖
1、導(dǎo)入數(shù)據(jù)

創(chuàng)新互聯(lián)專注于中山網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供中山營銷型網(wǎng)站建設(shè),中山網(wǎng)站制作、中山網(wǎng)頁設(shè)計(jì)、中山網(wǎng)站官網(wǎng)定制、成都微信小程序服務(wù),打造中山網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供中山網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
import pandas as pd # Data analysis
import numpy as np # Scientific computing
import seaborn as sns # Statistical visualization
# 讀取數(shù)據(jù)
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、設(shè)置閾值
# 設(shè)置pvalue和logFC的閾值 cut_off_pvalue = 0.0000001 cut_off_logFC = 1
3、設(shè)置分組
#分組為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、繪制散點(diǎn)圖
#繪制散點(diǎn)圖
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、設(shè)置散點(diǎn)圖
#確定坐標(biāo)軸顯示范圍
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))# 設(shè)置x軸刻度
ax.set_yticks(range(ymin, ymax, 2))# 設(shè)置y軸刻度
ax.set_ylabel('-log10(pvalue)',fontweight='bold') # 設(shè)置y軸標(biāo)簽
ax.set_xlabel('log2(fold change)',fontweight='bold') # 設(shè)置x軸標(biāo)簽以上就是python中畫火山圖的方法,希望能對(duì)大家有所幫助,更多知識(shí)盡在python學(xué)習(xí)網(wǎng)。
分享名稱:創(chuàng)新互聯(lián)Python教程:python中如何畫火山圖
文章鏈接:http://m.fisionsoft.com.cn/article/djhhgio.html


咨詢
建站咨詢
