plt画一个带注释的veen图
2022-03-17 本文已影响0人
倪桦
image.png
import matplotlib.pyplot as plt
import venn
import random
plt.figure(figsize=(32,12),edgecolor='k')
labels = venn.get_labels([set(reAnno_genelist),set(raw_genelist)],fill=['number','percent'],) ##set(reAnno_genelist)和set(raw_genelist)是输入的用于比较的两个基因集
fig, ax = venn.venn2(labels,
names=['reAnno_genelist','raw_genelist'],
fontsize=12,#控制组名及中间数字大小
)
plt.legend(labels=['ReAnno_genelist','raw_genelist'],bbox_to_anchor=(0.72, 0.2),ncol=2) #修改图例
#添加图片注释
plt.text(0.1, 0.78, "ReAnno_genelist :"+str(len(reAnno_genelist)), fontsize=15)
plt.text(0.7, 0.78, "Raw_genelist :"+str(len(raw_genelist)), fontsize=15)
reAnno_genelist_uniq_sample = random.sample(set(reAnno_genelist_uniq), 30)
text_1 = '\n '.join([str(e) for e in [reAnno_genelist_uniq_sample[i:i + 2] for i in range(0, len(reAnno_genelist_uniq_sample), 2)]])
plt.annotate(text_1,xy = (0.3,0.4),xycoords = 'data',xytext= (-300,-150),textcoords = 'offset points',fontsize = 10,
bbox=dict(boxstyle='round,pad=0.5', fc='gray', alpha=0.08),
arrowprops = dict(arrowstyle = '->',connectionstyle = 'arc3,rad = .2'),
)
raw_genelist_uniq_sample = random.sample(set(raw_genelist_uniq), 30)
text_2 = '\n '.join([str(e) for e in [raw_genelist_uniq_sample[i:i + 3] for i in range(0, len(raw_genelist_uniq_sample), 3)]])
plt.annotate(text_2,xy = (0.7,0.4),xycoords = 'data',xytext= (+120,-180),textcoords = 'offset points',fontsize = 10,
bbox=dict(boxstyle='round,pad=0.5', fc='gray', alpha=0.08),
arrowprops = dict(arrowstyle = '->',connectionstyle = 'arc3,rad = -.2'),
)
##显示中文
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False
##
plt.title('基因集合',y=0.88,fontsize='xx-large',fontweight='heavy')
plt.savefig("diff_geneList_veen.jpg",dpi=300, bbox_inches = 'tight') #bbox_inches = 'tight' 设置用以完整保存图片