Python Venn图实际标签

时间:2019-04-10 23:53:46

标签: python matplotlib matplotlib-venn

我编写了以下代码来创建维恩图,以显示3个集合的交集。我所绘制的只是共同点的数量。我想要的是在交叉点内打印真实的A,B,C,...,而不计算它们。有办法吗?

我的代码和输出:

set1 = set(['A', 'B', 'C', 'D'])
set2 = set(['B', 'C', 'D', 'E'])
set3 = set(['C', 'D',' E', 'F', 'G'])
v=venn3([set1, set2, set3], ('Set1', 'Set2', 'Set3'))
plt.show()

enter image description here

我想要的是这样的:

enter image description here

1 个答案:

答案 0 :(得分:1)

See https://stackoverflow.com/a/55718006/11346909

Here's a personalized demonstration:

import matplotlib.pyplot as plt
from matplotlib_venn import venn3

set1 = set(['A', 'B', 'C', 'D'])
set2 = set(['B', 'C', 'D', 'E'])
set3 = set(['C', 'D',' E', 'F', 'G'])

venn = venn3([set1, set2, set3], ('Set1', 'Set2', 'Set3'))

venn.get_label_by_id('100').set_text('\n'.join(set1-set2-set3))
venn.get_label_by_id('110').set_text('\n'.join(set1&set2-set3))
venn.get_label_by_id('010').set_text('\n'.join(set2-set3-set1))
venn.get_label_by_id('101').set_text('\n'.join(set1&set3-set2))
venn.get_label_by_id('111').set_text('\n'.join(set1&set2&set3))
venn.get_label_by_id('011').set_text('\n'.join(set2&set3-set1))
venn.get_label_by_id('001').set_text('\n'.join(set3-set2-set1))

plt.show()

enter image description here