I have two lists of the same length of 0s and 1s: e.g. a = [0,0,0,1,1,0,1], b = [0,1,0,1,0,1,1] and want to get a Venn diagram which has the intersection as the sum of values which are both 1, so in this case 2 values would be 1 in the same position. How can I achieve this?

Thanks in advance!

I tried something like venn2(subsets = df['a']==1, df['b']==1, set_labels = ('a', 'b'), alpha = 0.5)

but it didn't work.

1

There are 1 best solutions below

0
On

You need to implement the logic to count the elements in each subset and pass the result in a tuple as the subsets parameter.

import pandas as pd
from matplotlib_venn import venn2
from matplotlib import pyplot as plt

data = { "A": [0,0,0,1,1,0,1], "B": [0,1,0,1,0,1,1] }

df = pd.DataFrame(data)

# Create tuple to store number of elements in each subset
subsets_data = (len(df[df['A']==1]), 
                len(df[df['B']==1]), 
                len(df[(df['A']==1) & (df['B']==1)]))

venn2(subsets=subsets_data, set_labels = ('A', 'B'), alpha = 0.5)