matplotlib-venn


Namematplotlib-venn JSON
Version 0.11.10 PyPI version JSON
download
home_pagehttps://github.com/konstantint/matplotlib-venn
SummaryFunctions for plotting area-proportional two- and three-way Venn diagrams in matplotlib.
upload_time2024-01-27 22:57:29
maintainer
docs_urlNone
authorKonstantin Tretyakov
requires_python
licenseMIT
keywords matplotlib plotting charts venn-diagrams
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            ====================================================
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

Dependencies
------------

- ``numpy``,
- ``scipy``,
- ``matplotlib``.

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 list ``(Ab, aB, AB)`` of subset sizes,
e.g.::

    venn2(subsets = (3, 2, 1))

and draw a two-circle venn diagram with respective region areas. In
the particular 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``. Alternatively, you can simply
provide a list 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 list of subset sizes ``(Abc, aBc, ABc, abC, AbC, aBC,
ABC)``, and draw a three-circle area-weighted venn
diagram. Alternatively, you can provide a list of three ``set`` or ``Counter`` objects
(rather than counting sizes for all 7 subsets).

The functions ``venn2_circles`` and ``venn3_circles`` draw just the
circles, whereas the functions ``venn2`` and ``venn3`` draw the
diagrams as a collection of colored patches, annotated with text
labels. In addition (version 0.7+), functions ``venn2_unweighted`` and
``venn3_unweighted`` draw the Venn diagrams without area-weighting.

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, however in most cases the picture will still
provide a decent indication.

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 (new in version 0.6)::

    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()


Questions
---------
* If you ask your questions at `StackOverflow <http://stackoverflow.com/>`_ and tag them `matplotlib-venn <http://stackoverflow.com/questions/tagged/matplotlib-venn>`_, chances are high you'll 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
  <https://pypi.python.org/pypi/matplotlib-subsets>`_ package
  visualizes a hierarchy of sets as a tree of rectangles.
* The `matplotlib_venn_wordcloud <https://pypi.python.org/pypi/matplotlib_venn_wordcloud>`_ package
  combines Venn diagrams with word clouds for a pretty amazing (and amusing) result.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/konstantint/matplotlib-venn",
    "name": "matplotlib-venn",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "matplotlib plotting charts venn-diagrams",
    "author": "Konstantin Tretyakov",
    "author_email": "kt@umn.ee",
    "download_url": "https://files.pythonhosted.org/packages/61/fe/5a36da0d3dde780e2839f20934f7e0e8c8aea682a3de93bf6049e10d147f/matplotlib-venn-0.11.10.tar.gz",
    "platform": "Platform Independent",
    "description": "====================================================\r\nVenn diagram plotting routines for Python/Matplotlib\r\n====================================================\r\n\r\n.. image::  https://travis-ci.org/konstantint/matplotlib-venn.png?branch=master\r\n   :target: https://travis-ci.org/konstantint/matplotlib-venn\r\n\r\nRoutines for plotting area-weighted two- and three-circle venn diagrams.\r\n\r\nInstallation\r\n------------\r\n\r\nInstall the package as usual via ``pip``::\r\n\r\n    $ python -m pip install matplotlib-venn\r\n\r\nDependencies\r\n------------\r\n\r\n- ``numpy``,\r\n- ``scipy``,\r\n- ``matplotlib``.\r\n\r\nUsage\r\n-----\r\nThe package provides four main functions: ``venn2``,\r\n``venn2_circles``, ``venn3`` and ``venn3_circles``.\r\n\r\nThe functions ``venn2`` and ``venn2_circles`` accept as their only\r\nrequired argument a 3-element list ``(Ab, aB, AB)`` of subset sizes,\r\ne.g.::\r\n\r\n    venn2(subsets = (3, 2, 1))\r\n\r\nand draw a two-circle venn diagram with respective region areas. In\r\nthe particular example, the region, corresponding to subset ``A and\r\nnot B`` will be three times larger in area than the region,\r\ncorresponding to subset ``A and B``. Alternatively, you can simply\r\nprovide a list of two ``set`` or ``Counter`` (i.e. multi-set) objects instead (new in version 0.7),\r\ne.g.::\r\n\r\n    venn2([set(['A', 'B', 'C', 'D']), set(['D', 'E', 'F'])])\r\n\r\nSimilarly, the functions ``venn3`` and ``venn3_circles`` take a\r\n7-element list of subset sizes ``(Abc, aBc, ABc, abC, AbC, aBC,\r\nABC)``, and draw a three-circle area-weighted venn\r\ndiagram. Alternatively, you can provide a list of three ``set`` or ``Counter`` objects\r\n(rather than counting sizes for all 7 subsets).\r\n\r\nThe functions ``venn2_circles`` and ``venn3_circles`` draw just the\r\ncircles, whereas the functions ``venn2`` and ``venn3`` draw the\r\ndiagrams as a collection of colored patches, annotated with text\r\nlabels. In addition (version 0.7+), functions ``venn2_unweighted`` and\r\n``venn3_unweighted`` draw the Venn diagrams without area-weighting.\r\n\r\nNote that for a three-circle venn diagram it is not in general\r\npossible to achieve exact correspondence between the required set\r\nsizes and region areas, however in most cases the picture will still\r\nprovide a decent indication.\r\n\r\nThe functions ``venn2_circles`` and ``venn3_circles`` return the list of ``matplotlib.patch.Circle`` objects that may be tuned further\r\nto your liking. The functions ``venn2`` and ``venn3`` return an object of class ``VennDiagram``,\r\nwhich gives access to constituent patches, text elements, and (since\r\nversion 0.7) the information about the centers and radii of the\r\ncircles.\r\n\r\nBasic Example::\r\n\r\n    from matplotlib_venn import venn2\r\n    venn2(subsets = (3, 2, 1))\r\n\r\nFor the three-circle case::\r\n\r\n    from matplotlib_venn import venn3\r\n    venn3(subsets = (1, 1, 1, 2, 1, 2, 2), set_labels = ('Set1', 'Set2', 'Set3'))\r\n\r\nA more elaborate example::\r\n\r\n    from matplotlib import pyplot as plt\r\n    import numpy as np\r\n    from matplotlib_venn import venn3, venn3_circles\r\n    plt.figure(figsize=(4,4))\r\n    v = venn3(subsets=(1, 1, 1, 1, 1, 1, 1), set_labels = ('A', 'B', 'C'))\r\n    v.get_patch_by_id('100').set_alpha(1.0)\r\n    v.get_patch_by_id('100').set_color('white')\r\n    v.get_label_by_id('100').set_text('Unknown')\r\n    v.get_label_by_id('A').set_text('Set \"A\"')\r\n    c = venn3_circles(subsets=(1, 1, 1, 1, 1, 1, 1), linestyle='dashed')\r\n    c[0].set_lw(1.0)\r\n    c[0].set_ls('dotted')\r\n    plt.title(\"Sample Venn diagram\")\r\n    plt.annotate('Unknown set', xy=v.get_label_by_id('100').get_position() - np.array([0, 0.05]), xytext=(-70,-70),\r\n                 ha='center', textcoords='offset points', bbox=dict(boxstyle='round,pad=0.5', fc='gray', alpha=0.1),\r\n                 arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0.5',color='gray'))\r\n    plt.show()\r\n\r\nAn example with multiple subplots (new in version 0.6)::\r\n\r\n    from matplotlib_venn import venn2, venn2_circles\r\n    figure, axes = plt.subplots(2, 2)\r\n    venn2(subsets={'10': 1, '01': 1, '11': 1}, set_labels = ('A', 'B'), ax=axes[0][0])\r\n    venn2_circles((1, 2, 3), ax=axes[0][1])\r\n    venn3(subsets=(1, 1, 1, 1, 1, 1, 1), set_labels = ('A', 'B', 'C'), ax=axes[1][0])\r\n    venn3_circles({'001': 10, '100': 20, '010': 21, '110': 13, '011': 14}, ax=axes[1][1])\r\n    plt.show()\r\n\r\nPerhaps the most common use case is generating a Venn diagram given\r\nthree sets of objects::\r\n\r\n    set1 = set(['A', 'B', 'C', 'D'])\r\n    set2 = set(['B', 'C', 'D', 'E'])\r\n    set3 = set(['C', 'D',' E', 'F', 'G'])\r\n\r\n    venn3([set1, set2, set3], ('Set1', 'Set2', 'Set3'))\r\n    plt.show()\r\n\r\n\r\nQuestions\r\n---------\r\n* If you ask your questions at `StackOverflow <http://stackoverflow.com/>`_ and tag them `matplotlib-venn <http://stackoverflow.com/questions/tagged/matplotlib-venn>`_, chances are high you'll get an answer from the maintainer of this package.\r\n\r\n\r\nSee also\r\n--------\r\n\r\n* Report issues and submit fixes at Github:\r\n  https://github.com/konstantint/matplotlib-venn\r\n  \r\n  Check out the ``DEVELOPER-README.rst`` for development-related notes.\r\n* Some alternative means of plotting a Venn diagram (as of\r\n  October 2012) are reviewed in the blog post:\r\n  http://fouryears.eu/2012/10/13/venn-diagrams-in-python/\r\n* The `matplotlib-subsets\r\n  <https://pypi.python.org/pypi/matplotlib-subsets>`_ package\r\n  visualizes a hierarchy of sets as a tree of rectangles.\r\n* The `matplotlib_venn_wordcloud <https://pypi.python.org/pypi/matplotlib_venn_wordcloud>`_ package\r\n  combines Venn diagrams with word clouds for a pretty amazing (and amusing) result.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Functions for plotting area-proportional two- and three-way Venn diagrams in matplotlib.",
    "version": "0.11.10",
    "project_urls": {
        "Homepage": "https://github.com/konstantint/matplotlib-venn"
    },
    "split_keywords": [
        "matplotlib",
        "plotting",
        "charts",
        "venn-diagrams"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b1f412ea88962cd17acb58bfcce1b93ce256f591698f9adb247de3eea630f590",
                "md5": "306edbce0aded5848d6b7d9bf056a746",
                "sha256": "85650429baff7a812b2785540979e6bf0abcc747e7fe5ffd2a972cb917a826d6"
            },
            "downloads": -1,
            "filename": "matplotlib_venn-0.11.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "306edbce0aded5848d6b7d9bf056a746",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 33191,
            "upload_time": "2024-01-27T22:57:27",
            "upload_time_iso_8601": "2024-01-27T22:57:27.768812Z",
            "url": "https://files.pythonhosted.org/packages/b1/f4/12ea88962cd17acb58bfcce1b93ce256f591698f9adb247de3eea630f590/matplotlib_venn-0.11.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "61fe5a36da0d3dde780e2839f20934f7e0e8c8aea682a3de93bf6049e10d147f",
                "md5": "6e5ec5522e798321c224337f07a085cd",
                "sha256": "90d0cfb279c5dbbdf7dfd722c0e2515a37f535e949bcad174483bc777e372e65"
            },
            "downloads": -1,
            "filename": "matplotlib-venn-0.11.10.tar.gz",
            "has_sig": false,
            "md5_digest": "6e5ec5522e798321c224337f07a085cd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 30509,
            "upload_time": "2024-01-27T22:57:29",
            "upload_time_iso_8601": "2024-01-27T22:57:29.638435Z",
            "url": "https://files.pythonhosted.org/packages/61/fe/5a36da0d3dde780e2839f20934f7e0e8c8aea682a3de93bf6049e10d147f/matplotlib-venn-0.11.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-27 22:57:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "konstantint",
    "github_project": "matplotlib-venn",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "matplotlib-venn"
}
        
Elapsed time: 0.38010s