python-韦恩图
具有两个分组的基本韦恩图
from matplotlib_venn import venn2
# 第一种方法,10,5为两组的大小,2为两组交叉大小;
# set_labels为组名
venn2(subsets = (10, 5, 2), set_labels = ('Group A', 'Group B'))
# 给定两组值,计算每组的长度和公共值的数量
venn2([set(['A', 'B', 'C', 'D']), set(['D', 'E', 'F'])], set_labels = ('Label A', 'Label B'))
具有三个分组的基本韦恩图
from matplotlib_venn import venn3
# 子集顺序:A、B、AB、C、AC、BC、ABC
venn3(subsets = (10, 8, 22, 6,9,4,2), set_labels=('Group A', 'Group B', 'Group C'))
# 设置三组ABCD、DEF、ADG
venn3([set(['A', 'B', 'C', 'D']), set(['D', 'E', 'F']), set(['A', 'D', 'G','F'])], set_labels=['Label A', 'Label B', 'Label C'])
自定义韦恩图
# 自定义韦恩图
from matplotlib_venn import venn3
from matplotlib_venn import venn3_circles
# Custom text labels: change the label of group A
v=venn3(subsets = (10, 8, 22, 6,9,4,2), set_labels = ('Group A', 'Group B', 'Group C'))
# 单独改变A的标签
v.get_label_by_id('A').set_text('My Favourite group!')
参考:
「1」https://blog.csdn.net/LuohenYJ/article/details/103091081
「2」https://github.com/konstantint/matplotlib-venn