Changing what is displayed inside a Venn diagram

Question:

I am using the Matplotlib_venn package to make a few Venn diagrams representing the overlaps of three different sets (hence using Venn3).

When I use plt.show() and create the Venn diagram, the numbers that are displayed on the inside of each part of each circle are the numbers of times an element in the sets fulfill that requirement of overlap. I get that.

My question is: Is there a way to instead of displaying this cardinality, display the elements of the set that exist in each of those circles? I imagine this would get really messy with large sets, but could you do this with say three sets all containing less than 5 elements in each set? If so, how would I do this?

Asked By: user7600729

||

Answers:

I think I just gotta use .get_label_by_id().set_text() to do it since there are only a few items as you said.

First, let get all the labels for each of the areas in a Venn diagram:

from matplotlib_venn import venn3

subsets = (1, 1, 0.2, 1, 0.2, 0.2, 0.1)
v = venn3(subsets=subsets)

labels = ['100', '101', '110', '010', '001', '011', '111']
for label in labels:
    v.get_label_by_id(label).set_text(label)

This will give you:

enter image description here

If you want to display the items (e.g., a, b, c, d) in the area labeled 100, you can use the following code:

v.get_label_by_id('100').set_text('a, b, c, d')

enter image description here

Answered By: steven