Registry / data / matplotlib-venn

matplotlib-venn

JSON →
library1.1.2pypypi✓ verified 85d ago

matplotlib-venn is a Python library that provides functions for plotting area-proportional two- and three-way Venn diagrams using Matplotlib. It enables visualization of set relationships with circles whose areas correspond to subset sizes. The current stable version is 1.1.2. The library sees active maintenance, with updates addressing functionality and dependencies, though not on a rapid fixed schedule.

pip install matplotlib-venn
INSTALL
IMPORT
SIG · MATPLOTLIB-VENN
M
matplotlib-venn
datapythonv1.1.2
Install
13.0s avg
Import
3604ms
Disk
335MB
Pass rate
9/ 10
Env Coverage9 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 12.76s
py 3.11
✓ —
✓ 12.58s
py 3.12
✓ —
✓ 12.39s
py 3.13
✓ —
✓ 12.33s
py 3.9
4/8 runs
✓ 14.83s
335MB installed
● package 335MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

venn2
from matplotlib_venn import venn2
venn2_circles
from matplotlib_venn import venn2_circles
venn3
from matplotlib_venn import venn3
venn3_circles
from matplotlib_venn import venn3_circles

This example demonstrates how to create both two-set and three-set Venn diagrams. The two-set diagram uses explicit subset counts, while the three-set diagram uses actual set objects for input. Both examples utilize `pyplot.show()` to display the generated diagrams.

from matplotlib_venn import venn2 from matplotlib import pyplot as plt # Create a two-set Venn diagram with subset sizes venn2(subsets=(3, 2, 1), set_labels=('Group A', 'Group B')) plt.title("Basic Two-set Venn Diagram") plt.show() # Create a three-set Venn diagram from sets set1 = set(['A', 'B', 'C', 'D']) set2 = set(['B', 'C', 'D', 'E']) set3 = set(['C', 'D', 'E', 'F', 'G']) venn3([set1, set2, set3], ('Set1', 'Set2', 'Set3')) plt.title("Three-set Venn Diagram from Data") plt.show()
Debug
Known issues
gotchaFor three-circle Venn diagrams (`venn3`), it is not always mathematically possible to achieve exact correspondence between required subset sizes and region areas due to the geometric constraints of circles. The layout algorithm prioritizes accurate representation of overall set and pairwise intersection areas.
fix
Be aware that visual proportionality for all 7 regions in `venn3` might not be perfect, especially with highly disparate subset sizes. For exact representation, consider alternative visualizations or other libraries like `matplotlib_set_diagrams` or `supervenn` for more than three sets.
affects: All versions
deprecatedThe `shapely` package, currently an optional dependency for the 'cost-based' layout algorithm in `venn3` (since version 1.1.0), is likely to become a required dependency in a future version. This could lead to breaking changes if not installed proactively.
fix
It is recommended to install `matplotlib-venn` with the `shapely` extra: `pip install "matplotlib-venn[shapely]"` to ensure access to all features and prepare for future dependency changes.
affects: >=1.1.0
gotchaWhen `set_labels` are not explicitly provided to `venn2` or `venn3`, the diagrams will default to generic labels like 'A', 'B', 'C'. This can lead to misleading or uninformative plots, especially in a data analysis context.
fix
Always provide meaningful labels for your sets using the `set_labels` parameter, e.g., `venn2(subsets=(3,2,1), set_labels=('Set of Apples', 'Set of Bananas'))`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'matplotlib_venn'
The package was either not installed, or installed in a different environment, or an incorrect import path was used (e.g., trying to import `matplotlib-venn` directly instead of `matplotlib_venn`). This often occurs when using `conda install matplotlib-venn` without specifying the `conda-forge` channel.
fix
Ensure the package is installed in the active environment via `pip install matplotlib-venn` or, for Conda users, `conda install -c conda-forge matplotlib-venn`. Verify the import statement: `from matplotlib_venn import venn2` (note the underscore).
Venn diagram does not display or appear in Jupyter/script output.
In non-interactive environments (like scripts) or Jupyter Notebooks, Matplotlib figures require an explicit command to be shown or saved. Without `plt.show()` or saving the figure, the plot is generated but not rendered.
fix
Always include `import matplotlib.pyplot as plt` and `plt.show()` at the end of your plotting code to display the generated Venn diagram. In Jupyter, ensure `%matplotlib inline` or `%matplotlib notebook` is set if interactive plots are desired.
Distorted or poorly laid out venn3 diagram, especially with zero or very small subset values.
The mathematical complexity of area-proportional three-circle Venn diagrams can lead to suboptimal layouts or even regions not appearing when subset sizes are zero or extremely disproportionate, as the algorithm struggles to balance all constraints.
fix
Consider 'regularizing' the subset areas by adding a small constant value to all regions, especially if some are zero. If area proportionality is critical and visuals are distorted, manually adjust label positions (`v.get_label_by_id().set_position()`) or consider alternative visualization methods for more complex set relationships.
Upgrade
Version history
1.1.2latest on PyPI · released Feb 25, 2025
Audit
Dependencies
numpyrequiredCore numerical operations for diagram calculations.
scipyrequiredUsed for scientific computing and underlying algorithms.
matplotlibrequiredThe primary plotting library for rendering Venn diagrams.
shapelyoptionalProvides a 'cost-based' layout algorithm for venn3 diagrams, improving area proportionality. May become a required dependency in future versions (since 1.1.0).
Agent activity
4 hits · last 30 days
node
4
Resources
matplotlib-venn — pip install matplotlib-venn · libregistry