{"id":8302,"library":"matplotlib-venn","title":"Matplotlib Venn","description":"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.","status":"active","version":"1.1.2","language":"en","source_language":"en","source_url":"https://github.com/konstantint/matplotlib-venn","tags":["matplotlib","venn","diagrams","visualization","data science","statistics","sets"],"install":[{"cmd":"pip install matplotlib-venn","lang":"bash","label":"Standard installation"},{"cmd":"pip install \"matplotlib-venn[shapely]\"","lang":"bash","label":"With optional shapely dependency for improved venn3 layout"},{"cmd":"conda install -c conda-forge matplotlib-venn","lang":"bash","label":"Conda installation via conda-forge"}],"dependencies":[{"reason":"Core numerical operations for diagram calculations.","package":"numpy","optional":false},{"reason":"Used for scientific computing and underlying algorithms.","package":"scipy","optional":false},{"reason":"The primary plotting library for rendering Venn diagrams.","package":"matplotlib","optional":false},{"reason":"Provides a 'cost-based' layout algorithm for venn3 diagrams, improving area proportionality. May become a required dependency in future versions (since 1.1.0).","package":"shapely","optional":true}],"imports":[{"symbol":"venn2","correct":"from matplotlib_venn import venn2"},{"symbol":"venn2_circles","correct":"from matplotlib_venn import venn2_circles"},{"symbol":"venn3","correct":"from matplotlib_venn import venn3"},{"symbol":"venn3_circles","correct":"from matplotlib_venn import venn3_circles"}],"quickstart":{"code":"from matplotlib_venn import venn2\nfrom matplotlib import pyplot as plt\n\n# Create a two-set Venn diagram with subset sizes\nvenn2(subsets=(3, 2, 1), set_labels=('Group A', 'Group B'))\nplt.title(\"Basic Two-set Venn Diagram\")\nplt.show()\n\n# Create a three-set Venn diagram from sets\nset1 = set(['A', 'B', 'C', 'D'])\nset2 = set(['B', 'C', 'D', 'E'])\nset3 = set(['C', 'D', 'E', 'F', 'G'])\nvenn3([set1, set2, set3], ('Set1', 'Set2', 'Set3'))\nplt.title(\"Three-set Venn Diagram from Data\")\nplt.show()","lang":"python","description":"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."},"warnings":[{"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.","message":"For 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The `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.","severity":"deprecated","affected_versions":">=1.1.0"},{"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'))`.","message":"When `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"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).","cause":"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.","error":"ModuleNotFoundError: No module named 'matplotlib_venn'"},{"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.","cause":"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.","error":"Venn diagram does not display or appear in Jupyter/script output."},{"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.","cause":"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.","error":"Distorted or poorly laid out venn3 diagram, especially with zero or very small subset values."}]}