Venn Diagram

logo of a chart:Venn

A Venn Diagram (also called primary diagram, set diagram or logic diagram) is a diagram that shows all possible logical relationships between a finite collection of different sets. Fortunately, the matplotlib_venn library allows to build one easily with Python.

⏱ Quick start

The venn2 function of the matplotlib_venn library is the best way to make a Venn Diagram with Python, as shown on the code below.

Note that several input formats are possible to get there. This first post of the section goes through them and should get you started from any kind of input. 🔥

Most basic Venn Diagram with Python

Most basic Venn Diagram with Python

# library
import matplotlib.pyplot as plt
from matplotlib_venn import venn2

# Use the venn2 function
venn2(subsets = (10, 5, 2), set_labels = ('Group A', 'Group B'))
plt.show()

ℹ ️ A note on the Matplotlib-venn library

The matplotlib-venn library has been created by Konstantin Tretyakov. Its official documentation is available on github. Take a minute to give him a ⭐ if you use it!

Matplotlib-venn documentation

Matplotlib logoVenn Diagram with Matplotlib and matplotlib-venn

Matplotlib is probably the most famous and flexible python library for data visualization. It is appropriate to build any kind of chart, including the lollipop plot thanks to its stem() function.

The Venn2() function allows to customize the venn diagram as much as you want, allowing to build some pretty neat figures as below:

Upset plot as an alternative

Venn diagrams are great to visualize the intersection between 2 or 3 sets. Above that they become quite messy and unreadable.

There is a alternative to them: the upSet plot that can be made thanks to the upSetPlot library

Show me!

🚨 Grab the Data To Viz poster!

Do you know all the chart types? Do you know which one you should pick? I made a decision tree that answers those questions. You can download it for free!

dataviz decision tree poster