Search code examples
pythonmatplotlibvenn-diagrammatplotlib-venn

Finding intersect values using Python matplotlib-venn


I've been using matplotlib-venn to generate a venn diagram of 3 sets. Shown below.

I wanted to ask how can find the values of the intersects of these sets. For example, what are the 384 values that intersect set A and set B? What are the 144 values that intersect set A, set B, and set C? and so worth.

Thank you.

Rodrigo

Matplotlib-venn diagram


Solution

  • Assuming you are using builtin Python set objects, it is very simple to obtain the intersection between two sets. See this example:

    >>> a = set(range(30))
    >>> b = set(range(25,50))
    >>> a.intersection(b)
    set([25, 26, 27, 28, 29])