Elly O
Elly O

Reputation: 11

Creating Venn Diagrams with Categorical Data- matplotlib_venn

I'd like to use Python 3 to make a Venn diagram to show categorical data. If I do, say

  Rosy = ["chocolate", "chips", "cake", "sweets"]
  Steven = ["chocolate", "crisps", "nuggets"]

  venn2([set(Rosy), set(Steven)])
  plt.show()

Then I get a diagram with the number of entries corresponding to each segment but what I'd like is the actual entries in each segment (i.e. chips, cake sweets in the just Rosy bit, chocolate in the intersection and crisps and nuggets in Steven's bit). Is there any way of doing this using matplotlib_venn?

Upvotes: 1

Views: 960

Answers (1)

ChaosPredictor
ChaosPredictor

Reputation: 4071

The best way that I found is something like this:

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

v = venn2([set1, set2], ('Set1', 'Set2'))
v.get_label_by_id('10').set_text('\n A')
v.get_label_by_id('01').set_text('\n E')
v.get_label_by_id('11').set_text('\n \nB \nC \nD')
plt.show()

Just create functions that generate the texts from set1 & set2 for set_text on the fly and it's done. enter image description here

Upvotes: 1

Related Questions