Seaborn学习框架
General form
Function(x= , y= , data= , hue= )
data=dataframe数据
x=
y=
kind=
col= # 分栏
hue=分类
hue_order=('up','unchange','down') # 分类顺序
palette=['red','gray','blue'] # 分类颜色(按照分类顺序)
ci='sd' # std
style=‘*, #, ^, ...’ # 风格
size=(15, 20) # 尺寸
1. 基本绘图
1. 散点图:scatterplot(x= , y= , data= )
2. 线性图:lineplot(x= , y= , data= )
3. 通用式:relplot(kind='scatter/line', x= , y= , data= )
2. Categorical Plots(分类)
1. categorical scatter plots:
分布散点图:stripplot()
分布密度散点图:swarmplot() #功能同上,仅不覆盖
2. categorical distribution plots:
分布箱线图:boxplot()
分布小提琴图:violinplot()
3. categorical estimate plots:
pointplot()
barplot()
countplot()
4. 通用式:
catplot(kind='strip/swarm/box/violin/point/bar/count', x= , y= , data= )
3. Distribution Plots(分布/直方)
1. 直方图:displot()
2. 核密度图:kdeplot() #kernel="gau..." :高斯分布
3. 联合分布图:joinplot() #kind="kde/strip..."
4. 变量关系图:pairplot() #探索变量间==两两关系==
4. Regression Plots(回归)
1. Implot()
5. Matrix Plots(矩阵)
1. heatmap()
2. clustermap()
6. FaceGrid
7. PairGrid
8. Theme
sns.set_style(‘white’) #白色网格背景
9. Color
10.Tips
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 23 08:48:58 2020
@author: Bio-windows
"""
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
def picture1():
'''the one way'''
x = np.linspace(0,20)
y1 = x
y2 = x**2
y3 = x**3
fig,ax = plt.subplots(2,2)
fig.subplots_adjust(wspace=0.5, hspace=0.5)
sns.scatterplot(x,y1,ax=ax[0,0])
ax[0,0].set_title('liner')
sns.lineplot(x,y2,ax=ax[0,1])
ax[0,1].set_title('平方')
sns.lineplot(x,y3,ax=ax[1,0])
ax[1,0].set_title('三次方')
return None
def picture2():
'''the 2nd way'''
x = np.linspace(0,20)
y1 = x
y2 = x**2
y3 = x**3
fig = plt.figure()
fig.add_subplot(211)
sns.scatterplot(x,y1)
plt.title('liner')
fig.add_subplot(223)
sns.lineplot(x,y3)
plt.title('cifang')
fig.add_subplot(224)
sns.lineplot(x,y2)
plt.title('sancifang')
return None
def picture3():
'''the 2nd way'''
x = np.linspace(0,20)
y1 = x
y2 = x**2
y3 = x**3
fig = plt.figure(figsize=(8,8))
ax = fig.add_subplot(211)
sns.scatterplot(x,y1,ax=ax)
ax.set_title('liner')
ax.set_xlabel('x')
ax.set_ylabel('y1')
ax = fig.add_subplot(223)
sns.lineplot(x,y2,ax=ax)
ax.set_title('liner')
ax.set_title('ercifang')
ax = fig.add_subplot(224)
sns.lineplot(x,y3,ax=ax)
ax.set_title('sancifang')
return None
if __name__ == '__main__':
'''main function'''
sns.set_palette('Set2')
picture1()
picture2()
picture3()
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 23 19:15:43 2020
@author: Bio-windows
"""
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
def sig_src(thr_num,sig_num):
'''筛选差异基因'''
dge = pd.read_excel('D:/workstations/组学分析/蛋白质组学/3492报告及附件/报告及附件/3-2表达差异分析/3-2-1差异结果数量统计/附件3_蛋白质定量和差异分析列表.xlsx')
for i in dge.index:
if (dge.loc[i,'mutant1P/WT1P'] >= thr_num )& (dge.loc[i,'t test p value'] < sig_num):
dge.loc[i,'sig'] = 'up'
elif (dge.loc[i,'mutant1P/WT1P'] <= (1/thr_num)) & (dge.loc[i,'t test p value'] < sig_num):
dge.loc[i,'sig'] = 'down'
else:
dge.loc[i,'sig'] = 'unchange'
FdPvalue = dge[(dge['sig']=='up') | (dge['sig']=='down')]
FdPvalue.to_csv('FoldChange'+str(thr_num)+'Pvalue'+str(sig_num)+'.csv')
return dge,thr_num
def picture(x,ax):
dge,thr_num = x
sns.scatterplot(data=dge,\
x=np.log2(dge['mutant1P/WT1P']),\
y=-np.log10(dge['t test p value']),\
hue='sig',hue_order=('up','unchange','down'),palette=['red','gray','blue'],ax=ax)
ax.set_title('FoldChange='+str(thr_num))
ax.set_xlabel('log2(mutant1P/WT1P)')
ax.set_ylabel('-log10(t test p value)')
if __name__ == '__main__':
'''main function'''
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(221)
picture(sig_src(thr_num=1.2,sig_num=0.05),ax)
ax = fig.add_subplot(222)
picture(sig_src(thr_num=1.5,sig_num=0.05),ax)
ax = fig.add_subplot(223)
picture(sig_src(thr_num=1.8,sig_num=0.05),ax)
ax = fig.add_subplot(224)
picture(sig_src(thr_num=2,sig_num=0.05),ax)
fig.savefig('DGE.png',dpi=300,format='png')