Matplotlib Venn Plotting with Examples : An easy explanation

Matplotlib Venn Plotting with Examples

Matplotlib Venn plotting visualizes the number sets. Here, We will see how can we plot a Venn diagram in python using matplotlib-Venn in steps.

Matplotlib Venn plotting Steps :

We will simply draw the matplotlib Venn chart in steps. In order to demonstrate this, We will take two sets.

unique elements of A=15,

unique elements of B=10,

The common element of A AND B =5

Now we will see how to plot the Venn diagram in python.

Step 1: Installing the library

In order to draw the Venn diagram in python. You need to install the matplotlib-Venn Library/python package. We can install it via the below command.

pip install matplotlib-venn

You may use a different package manager for installing this library.

Step 2: Importing packages

We will import these below packages.

from matplotlib_venn import venn2
from matplotlib import pyplot as plt
%matplotlib inline

We need matplotlib for basic plotting. Also venn2 for specifically Venn diagrams.


Step 3: Plotting diagram

In this step, We will plot the final diagram. Here we need to call the venn2() with arguments. Let’s see them.

venn2(subsets = (15, 10, 5), set_labels = ('A', 'B'))


In the above example, We have seen that the venn() function requires few parameters. Like

1. Subset : ( A, B, A AND B) It is reordering as per our example. Unique elements of A is 15 and B is 10, and common are 5 in numbers.


2. set_labels: Strings for nominations. Here have used A and B in the above example. But in real scenarios, it will be a meaningful name.

Complete Code –

In this section, We will merge the complete code.

from matplotlib_venn import venn2
from matplotlib import pyplot as plt
%matplotlib inline
venn2(subsets = (15, 10, 5), set_labels = ('A', 'B'))

Here is the output for that.

Matplotlib venn
Matplotlib venn


Conclusion –

Venn diagram is the best way to visualize the sets. In this article, We have seen the implementation of venn diagram in python with a minimal example. We have also described each step and most are self-explanatory to draw a Venn diagram. But if you feel anything doubtful in the complete article, Please let us know.


Data Science Learner Team

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Abhishek ( Chief Editor) , a data scientist with major expertise in NLP and Text Analytics. He has worked on various projects involving text data and have been able to achieve great results. He is currently manages, where he and his team share knowledge and help others learn more about data science.
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner