散点图

import pandas as pd 
import matplotlib.pyplot as plt 


##绘制散点图
data=pd.read_csv(dirPath+"/8DPA_AllChrs_permute_out.txt",header=None,index_col=0,sep="\t")
#! init the figure
plt.figure(figsize=(5, 5), dpi=600)
#! input list
empricial_pvalue=data[16]
beta_pvalue=data[17]
#! plot scatter
plt.scatter(empricial_pvalue, beta_pvalue)
plt.xlabel("Direct method", fontdict={'size': 16})
plt.ylabel("Beta approximation",fontdict={'size': 16})
#! save  the figure
plt.tight_layout() ## tight arranged
plt.savefig(outDir+"/8DPA_beta_empricial.pdf",dpi=600)
plt.show()

添加指定斜率和截距的直线

import pandas as pd 
import matplotlib.pyplot as plt 
import numpy as np 

def abline(slope, intercept, pltObject): 
    """Plot a line from slope and intercept""" 
    axes = pltObject.gca() 
    x_vals = np.array(axes.get_xlim()) 
    y_vals = intercept + slope * x_vals 
    pltObject.plot(x_vals, y_vals, '-',color='red') 

#! 调用函数
abline(1,0,plt)

Last updated