matplotlib-venn
Area-weighted venn-diagrams for Python/matplotlib
Science Score: 36.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
1 of 8 committers (12.5%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.3%) to scientific vocabulary
Keywords
Repository
Area-weighted venn-diagrams for Python/matplotlib
Basic Info
- Host: GitHub
- Owner: konstantint
- License: mit
- Language: Jupyter Notebook
- Default Branch: master
- Size: 1.93 MB
Statistics
- Stars: 550
- Watchers: 10
- Forks: 68
- Open Issues: 6
- Releases: 0
Topics
Metadata Files
README.rst
====================================================
Venn diagram plotting routines for Python/Matplotlib
====================================================
.. image:: https://travis-ci.org/konstantint/matplotlib-venn.png?branch=master
:target: https://travis-ci.org/konstantint/matplotlib-venn
Routines for plotting area-weighted two- and three-circle venn diagrams.
Installation
------------
Install the package as usual via ``pip``::
$ python -m pip install matplotlib-venn
Since version 1.1.0 the package includes an extra "cost based" layout algorithm for `venn3` diagrams,
that relies on the `shapely` package, which is not installed as a default dependency. If you need the
new algorithm (or just have nothing against installing `shapely` along the way), instead do::
$ python -m pip install "matplotlib-venn[shapely]"
It is quite probable that `shapely` will become a required dependency eventually in one of the future versions.
Dependencies
------------
- ``numpy``,
- ``scipy``,
- ``matplotlib``,
- ``shapely`` (optional).
Usage
-----
The package provides four main functions: ``venn2``,
``venn2_circles``, ``venn3`` and ``venn3_circles``.
The functions ``venn2`` and ``venn2_circles`` accept as their only
required argument a 3-element tuple ``(Ab, aB, AB)`` of subset sizes,
and draw a two-circle venn diagram with respective region areas, e.g.::
venn2(subsets = (3, 2, 1))
In this example, the region, corresponding to subset ``A and not B`` will
be three times larger in area than the region, corresponding to subset ``A and B``.
You can also provide a tuple of two ``set`` or ``Counter`` (i.e. multi-set)
objects instead (new in version 0.7), e.g.::
venn2((set(['A', 'B', 'C', 'D']), set(['D', 'E', 'F'])))
Similarly, the functions ``venn3`` and ``venn3_circles`` take a
7-element tuple of subset sizes ``(Abc, aBc, ABc, abC, AbC, aBC,
ABC)``, and draw a three-circle area-weighted Venn
diagram:
.. image:: https://user-images.githubusercontent.com/13646666/87874366-96924800-c9c9-11ea-8b06-ac1336506b59.png
Alternatively, a tuple of three ``set`` or ``Counter`` objects may be provided.
The functions ``venn2`` and ``venn3`` draw the diagrams as a collection of colored
patches, annotated with text labels. The functions ``venn2_circles`` and
``venn3_circles`` draw just the circles.
The functions ``venn2_circles`` and ``venn3_circles`` return the list of ``matplotlib.patch.Circle`` objects that may be tuned further
to your liking. The functions ``venn2`` and ``venn3`` return an object of class ``VennDiagram``,
which gives access to constituent patches, text elements, and (since
version 0.7) the information about the centers and radii of the
circles.
Basic Example::
from matplotlib_venn import venn2
venn2(subsets = (3, 2, 1))
For the three-circle case::
from matplotlib_venn import venn3
venn3(subsets = (1, 1, 1, 2, 1, 2, 2), set_labels = ('Set1', 'Set2', 'Set3'))
A more elaborate example::
from matplotlib import pyplot as plt
import numpy as np
from matplotlib_venn import venn3, venn3_circles
plt.figure(figsize=(4,4))
v = venn3(subsets=(1, 1, 1, 1, 1, 1, 1), set_labels = ('A', 'B', 'C'))
v.get_patch_by_id('100').set_alpha(1.0)
v.get_patch_by_id('100').set_color('white')
v.get_label_by_id('100').set_text('Unknown')
v.get_label_by_id('A').set_text('Set "A"')
c = venn3_circles(subsets=(1, 1, 1, 1, 1, 1, 1), linestyle='dashed')
c[0].set_lw(1.0)
c[0].set_ls('dotted')
plt.title("Sample Venn diagram")
plt.annotate('Unknown set', xy=v.get_label_by_id('100').get_position() - np.array([0, 0.05]), xytext=(-70,-70),
ha='center', textcoords='offset points', bbox=dict(boxstyle='round,pad=0.5', fc='gray', alpha=0.1),
arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0.5',color='gray'))
plt.show()
An example with multiple subplots::
from matplotlib_venn import venn2, venn2_circles
figure, axes = plt.subplots(2, 2)
venn2(subsets={'10': 1, '01': 1, '11': 1}, set_labels = ('A', 'B'), ax=axes[0][0])
venn2_circles((1, 2, 3), ax=axes[0][1])
venn3(subsets=(1, 1, 1, 1, 1, 1, 1), set_labels = ('A', 'B', 'C'), ax=axes[1][0])
venn3_circles({'001': 10, '100': 20, '010': 21, '110': 13, '011': 14}, ax=axes[1][1])
plt.show()
Perhaps the most common use case is generating a Venn diagram given
three sets of objects::
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.show()
Tuning the diagram layout
-------------------------
Note that for a three-circle venn diagram it is not in general
possible to achieve exact correspondence between the required set
sizes and region areas. The default layout algorithm aims to correctly represent:
* Relative areas of the full individual sets (A, B, C).
* Relative areas of pairwise intersections of sets (A&B, A&C, B&C, not to be confused with the regions
A&B&~C, A&~B&C, ~A&B&C, on the diagram).
Sometimes the result is unsatisfactory and either the area weighting or the layout logic needs
to be tuned.
The area weighing can be adjusted by providing a `fixed_subset_sizes` argument to the `DefaultLayoutAlgorithm`::
from matplotlib_venn.layout.venn2 import DefaultLayoutAlgorithm
venn2((1,2,3), layout_algorithm=DefaultLayoutAlgorithm(fixed_subset_sizes=(1,1,1)))
from matplotlib_venn.layout.venn3 import DefaultLayoutAlgorithm
venn3((7,6,5,4,3,2,1), layout_algorithm=DefaultLayoutAlgorithm(fixed_subset_sizes=(1,1,1,1,1,1,1)))
In the above examples the diagram regions will be plotted as if `venn2((1,1,1))` and `venn3((1,1,1,1,1,1,1))` were
invoked, yet the actual numbers will be `(1,2,3)` and `(7,6,5,4,3,2,1)` respectively.
The diagram can be tuned further by switching the layout algorithm to a different implementation.
At the moment the package offers an alternative layout algorithm for `venn3` diagrams that lays the circles out by
optimizing a user-provided *cost function*. The following examples illustrate its usage::
from matplotlib_venn.layout.venn3 import cost_based
subset_sizes = (100,200,10000,10,20,3,1)
venn3(subset_sizes, layout_algorithm=cost_based.LayoutAlgorithm())
alg = cost_based.LayoutAlgorithm(cost_fn=cost_based.WeightedAggregateCost(transform_fn=lambda x: x))
venn3(subset_sizes, layout_algorithm=alg)
alg = cost_based.LayoutAlgorithm(cost_fn=cost_based.WeightedAggregateCost(weights=(0,0,0,1,1,1,1)))
venn3(subset_sizes, layout_algorithm=alg)
The default "pairwise" algorithm is, theoretically, a special case of the cost-based method with the respective cost function::
alg = cost_based.LayoutAlgorithm(cost_fn=cost_based.pairwise_cost)
venn3(subset_sizes, layout_algorithm=alg)
(The latter plot will be close, but not perfectly equal to the outcome of `DefaultLayoutAlgorithm()`).
Note that the import::
from matplotlib_venn.layout.venn3 import cost_based
will fail unless you have the optional `shapely` package installed (see "Installation" above).
Questions
---------
* If you ask your questions at `StackOverflow `_ and tag them
`matplotlib-venn `_, chances are high you could get
an answer from the maintainer of this package.
See also
--------
* Report issues and submit fixes at Github:
https://github.com/konstantint/matplotlib-venn
Check out the ``DEVELOPER-README.rst`` for development-related notes.
* Some alternative means of plotting a Venn diagram (as of
October 2012) are reviewed in the blog post:
http://fouryears.eu/2012/10/13/venn-diagrams-in-python/
* The `matplotlib-subsets
`_ package
visualizes a hierarchy of sets as a tree of rectangles.
* The `matplotlib_set_diagrams `_ package
is a GPL-licensed alternative that offers a different layout algorithm, which supports more than
three sets and provides a cool ability to incorporate wordclouds into your Venn (Euler) diagrams.
Owner
- Name: Konstantin Tretyakov
- Login: konstantint
- Kind: user
- Website: http://kt.era.ee
- Repositories: 63
- Profile: https://github.com/konstantint
GitHub Events
Total
- Issues event: 7
- Watch event: 44
- Delete event: 1
- Issue comment event: 12
- Push event: 3
- Pull request event: 1
- Fork event: 1
- Create event: 2
Last Year
- Issues event: 7
- Watch event: 44
- Delete event: 1
- Issue comment event: 12
- Push event: 3
- Pull request event: 1
- Fork event: 1
- Create event: 2
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Konstantin Tretyakov | kt@u****e | 64 |
| sinhrks | s****s@g****m | 3 |
| Elliott Sales de Andrade | q****t@g****m | 2 |
| Piotr Migdał | p****l@g****m | 1 |
| Jeffrey Do | j****o@f****m | 1 |
| Amit Saha | a****n@g****m | 1 |
| Ali Ebrahim | a****m@u****u | 1 |
| Konstantin Tretyakov | k****t@g****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 76
- Total pull requests: 13
- Average time to close issues: 5 months
- Average time to close pull requests: 2 months
- Total issue authors: 63
- Total pull request authors: 12
- Average comments per issue: 2.67
- Average comments per pull request: 1.69
- Merged pull requests: 7
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 7
- Pull requests: 2
- Average time to close issues: about 2 months
- Average time to close pull requests: N/A
- Issue authors: 7
- Pull request authors: 1
- Average comments per issue: 1.14
- Average comments per pull request: 1.0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- shinokada (6)
- felixlee0530 (4)
- konstantint (3)
- tillea (2)
- TheChymera (2)
- paulbrodersen (2)
- guillermomarco (1)
- EarthToMooney (1)
- nzjrs (1)
- fgypas (1)
- chetan201 (1)
- Sjok (1)
- jtlz2 (1)
- gemnsh (1)
- eafyounian (1)
Pull Request Authors
- mikado77-mrp (2)
- konstantint (2)
- amitsaha (1)
- olgabot (1)
- alexanderwhatley (1)
- stared (1)
- JohannesBuchner (1)
- QuLogic (1)
- aebrahim (1)
- sinhrks (1)
- Irfan-Ahmad-byte (1)
- jephdo (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 15
-
Total downloads:
- pypi 131,965 last-month
- Total docker downloads: 696,480
-
Total dependent packages: 55
(may contain duplicates) -
Total dependent repositories: 608
(may contain duplicates) - Total versions: 58
- Total maintainers: 2
pypi.org: matplotlib-venn
Functions for plotting area-proportional two- and three-way Venn diagrams in matplotlib.
- Homepage: https://github.com/konstantint/matplotlib-venn
- Documentation: https://matplotlib-venn.readthedocs.io/
- License: MIT
-
Latest release: 1.1.2
published 12 months ago
Rankings
Maintainers (1)
alpine-v3.18: py3-matplotlib-venn
Functions for plotting area-proportional two- and three-way Venn diagrams in matplotlib
- Homepage: https://github.com/konstantint/matplotlib-venn
- License: MIT
-
Latest release: 0.11.9-r1
published almost 3 years ago
Rankings
Maintainers (1)
alpine-v3.18: py3-matplotlib-venn-pyc
Precompiled Python bytecode for py3-matplotlib-venn
- Homepage: https://github.com/konstantint/matplotlib-venn
- License: MIT
-
Latest release: 0.11.9-r1
published almost 3 years ago
Rankings
Maintainers (1)
alpine-edge: py3-matplotlib-venn
Functions for plotting area-proportional two- and three-way Venn diagrams in matplotlib
- Homepage: https://github.com/konstantint/matplotlib-venn
- License: MIT
-
Latest release: 1.1.2-r0
published 12 months ago
Rankings
Maintainers (1)
alpine-edge: py3-matplotlib-venn-pyc
Precompiled Python bytecode for py3-matplotlib-venn
- Homepage: https://github.com/konstantint/matplotlib-venn
- License: MIT
-
Latest release: 1.1.2-r0
published 12 months ago
Rankings
Maintainers (1)
alpine-v3.17: py3-matplotlib-venn
Functions for plotting area-proportional two- and three-way Venn diagrams in matplotlib
- Homepage: https://github.com/konstantint/matplotlib-venn
- License: MIT
-
Latest release: 0.11.7-r1
published over 3 years ago
Rankings
Maintainers (1)
conda-forge.org: matplotlib-venn
- Homepage: https://github.com/konstantint/matplotlib-venn
- License: MIT
-
Latest release: 0.11.7
published almost 4 years ago
Rankings
alpine-v3.22: py3-matplotlib-venn-pyc
Precompiled Python bytecode for py3-matplotlib-venn
- Homepage: https://github.com/konstantint/matplotlib-venn
- License: MIT
-
Latest release: 1.1.2-r0
published 12 months ago
Rankings
Maintainers (1)
alpine-v3.19: py3-matplotlib-venn
Functions for plotting area-proportional two- and three-way Venn diagrams in matplotlib
- Homepage: https://github.com/konstantint/matplotlib-venn
- License: MIT
-
Latest release: 0.11.9-r3
published over 2 years ago
Rankings
alpine-v3.19: py3-matplotlib-venn-pyc
Precompiled Python bytecode for py3-matplotlib-venn
- Homepage: https://github.com/konstantint/matplotlib-venn
- License: MIT
-
Latest release: 0.11.9-r3
published over 2 years ago
Rankings
Maintainers (1)
alpine-v3.20: py3-matplotlib-venn-pyc
Precompiled Python bytecode for py3-matplotlib-venn
- Homepage: https://github.com/konstantint/matplotlib-venn
- License: MIT
-
Latest release: 0.11.10-r1
published almost 2 years ago
Rankings
Maintainers (1)
alpine-v3.21: py3-matplotlib-venn-pyc
Precompiled Python bytecode for py3-matplotlib-venn
- Homepage: https://github.com/konstantint/matplotlib-venn
- License: MIT
-
Latest release: 1.1.1-r0
published over 1 year ago
Rankings
Maintainers (1)
alpine-v3.21: py3-matplotlib-venn
Functions for plotting area-proportional two- and three-way Venn diagrams in matplotlib
- Homepage: https://github.com/konstantint/matplotlib-venn
- License: MIT
-
Latest release: 1.1.1-r0
published over 1 year ago
Rankings
Maintainers (1)
alpine-v3.22: py3-matplotlib-venn
Functions for plotting area-proportional two- and three-way Venn diagrams in matplotlib
- Homepage: https://github.com/konstantint/matplotlib-venn
- License: MIT
-
Latest release: 1.1.2-r0
published 12 months ago
Rankings
Maintainers (1)
alpine-v3.20: py3-matplotlib-venn
Functions for plotting area-proportional two- and three-way Venn diagrams in matplotlib
- Homepage: https://github.com/konstantint/matplotlib-venn
- License: MIT
-
Latest release: 0.11.10-r1
published almost 2 years ago
Rankings
Maintainers (1)
Dependencies
- matplotlib *
- numpy *
- scipy *