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-vennVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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'))`.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).
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.
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.