溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

使用python怎么繪制一個(gè)火山圖

發(fā)布時(shí)間:2021-04-27 16:38:22 來(lái)源:億速云 閱讀:424 作者:Leah 欄目:編程語(yǔ)言

今天就跟大家聊聊有關(guān)使用python怎么繪制一個(gè)火山圖,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

python的數(shù)據(jù)類型有哪些?

python的數(shù)據(jù)類型:1. 數(shù)字類型,包括int(整型)、long(長(zhǎng)整型)和float(浮點(diǎn)型)。2.字符串,分別是str類型和unicode類型。3.布爾型,Python布爾類型也是用于邏輯運(yùn)算,有兩個(gè)值:True(真)和False(假)。4.列表,列表是Python中使用最頻繁的數(shù)據(jù)類型,集合中可以放任何數(shù)據(jù)類型。5. 元組,元組用”()”標(biāo)識(shí),內(nèi)部元素用逗號(hào)隔開(kāi)。6. 字典,字典是一種鍵值對(duì)的集合。7. 集合,集合是一個(gè)無(wú)序的、不重復(fù)的數(shù)據(jù)組合。

1、導(dǎo)入數(shù)據(jù)

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)簽

看完上述內(nèi)容,你們對(duì)使用python怎么繪制一個(gè)火山圖有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI