Rebin
Rebin

Reputation: 526

Python Venn diagram actual label

I wrote the following code to create a Venn diagram to show the intersection of 3 sets. What I plot is just the numbers of elements in common. What I want is to print the real A,B,C,... inside the intersection not counting them. Is there a way?

my code and output:

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

What I want is something like this:

enter image description here

Upvotes: 3

Views: 4651

Answers (1)

Gabe
Gabe

Reputation: 995

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

Upvotes: 6

Related Questions