6

How can I create a venn diagram in python from 4 sets? Seems like the limit in matplotlib is only 3?

from matplotlib_venn import venn3

v = venn3(
    [
        set(ether_list),
        set(bitcoin_list),
        set(doge_list),
    ],
)
Nick Vence
  • 754
  • 1
  • 9
  • 19
heyzi1992
  • 73
  • 1
  • 3
  • 3
    "Seems like the limit in matplotlib is only 3" - Yes, because drawing it with 4 circles, each intersecting with each combination of the other 3 is impossible... You can draw it with more convoluted forms, like [this](https://math.gmu.edu/~eobrien/Venn4.html), but readability suffers... – Thierry Lathuille Apr 17 '22 at 13:15

2 Answers2

7

Venn diagrams with circles can work only with <4 sets, because the geometrical properties of intersections (some won't be possible to show). Some python libraries that allow you to show venn diagrams with more exotic shapes are:

rikyeah
  • 1,896
  • 4
  • 11
  • 21
0

There is a new python 3 package venny4py that can create Venn diagrams with up to 4 sets. It can plot and save figure or plot it as a subplot of your own matplotlib figure, figure size and dpi adjustable.

Example:

pip install venny4py

from venny4py.venny4py import *

#dict of sets
sets = {
    'Set1': set(list("Harry Potter")),
    'Set2': set(list("Hermione Granger")),
    'Set3': set(list("Ron Weasley")),
    'Set4': set(list("Severus Snape"))}
    
venny4py(sets=sets)

Venn diagram with 4 sets

More details can be found here

timanix
  • 94
  • 1
  • 3