Basic Venn diagram with 2 groups

logo of a chart:Venn

This post aims to show how to draw a basic venn diagram with an example using matplotlib library.

There are 2 main methods to make a Venn diagram with the matplotlib library, leading to the same result.

The first way is to pass directly the sizes of your groups and their intersection to the venn2() function. The second way is to pass 2 set of values to the function, and python will calculate itself the length of each set (=each group) and the number of common values (their intersection).

# library
import matplotlib.pyplot as plt
from matplotlib_venn import venn2
# First way to call the 2 group Venn diagram:
venn2(subsets = (10, 5, 2), set_labels = ('Group A', 'Group B'))
# Second way
venn2([set(['A', 'B', 'C', 'D']), set(['D', 'E', 'F'])])

Contact & Edit

👋 This document is a work by Yan Holtz. You can contribute on github, send me a feedback on twitter or subscribe to the newsletter to know when new examples are published! 🔥

This page is just a jupyter notebook, you can edit it here. Please help me making this website better 🙏!