• Stars
    star
    506
  • Rank 86,616 (Top 2 %)
  • Language
    Jupyter Notebook
  • License
    MIT License
  • Created almost 12 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Area-weighted venn-diagrams for Python/matplotlib

Venn diagram plotting routines for Python/Matplotlib

https://travis-ci.org/konstantint/matplotlib-venn.png?branch=master

Routines for plotting area-weighted two- and three-circle venn diagrams.

Installation

The simplest way to install the package is via easy_install or pip:

$ easy_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 and tag them matplotlib-venn, chances are high you'll get an answer from the maintainer of this package.

See also

More Repositories

1

PassportEye

Extraction of machine-readable zone information from passports, visas and id-cards via OCR
Python
372
star
2

SKompiler

A tool for compiling trained SKLearn models into other representations (such as SQL, Sympy or Excel formulas)
Python
171
star
3

pyliftover

Pure-python implementation of UCSC liftOver genome coordinate conversion
Python
87
star
4

eid-webauth-samples

eID Smart Card Web Authentication Samples
Shell
42
star
5

python-boilerplate-template

PasteScript template for initializing a new buildout/pytest/travis/setuptools-enabled Python project
Python
24
star
6

skype-chatsync-reader

Parser and GUI viewer of chatsync/\*.dat files from the Skype profile directory
Python
21
star
7

cookiecutter-flask-boilerplate

Boilerplate CookieCutter template for Flask web apps
JavaScript
19
star
8

ComputerGraphics2013

Materials (lecture slides and exercise sessions) for the course Computer Graphics (Fall 2013) at the University of Tartu
C++
13
star
9

hxAudio

Pitch detection and FFT in Haxe
Haxe
8
star
10

intervaltree-bio

Interval tree convenience classes for genomic data
Python
7
star
11

ipyslack

IPython magic for sending notifications to slack
Python
6
star
12

texata-finals-2017

The solution to the case study of the final round of the Texata Big Data Championship 2017
HTML
4
star
13

dotfiles-template

Dotfiles
Makefile
3
star
14

texata-finals-2014

The solution to the case study of the final round of the Texata Big Data Championship 2014
Python
3
star
15

PyENCODE

Python convenience package for accessing ENCODE (Encyclopedia of DNA Elements) project data at UCSC
Python
3
star
16

BreadboardBot

Build instructions and example code for a low-tech educational "robotic platform".
Python
2
star
17

bufalometro

Source code of bufalometro.it - a webapp for analysis of Italian text in the context of fake news detection
Jupyter Notebook
2
star
18

ArduinoSparkfunIRReceiver

Arduino library for using the SparkFun IR receiver breakout (http://www.sparkfun.com/products/8554)
C++
2
star
19

sail-the-wind

An interactive board for a sailing board game based on "Race the Wind"
JavaScript
2
star
20

RobotexSimulator2011

Simulator for the Robotex 2011
Python
2
star
21

steem-stats

Explorations of the Steem data
Jupyter Notebook
2
star
22

eio-pmwiki-skin

PmWiki skin for eio.ut.ee
CSS
1
star
23

pyce

PyCE comptational experiment management framework
Python
1
star
24

TeddyStick

An M5StickC application for use with TeddyCloud.
Python
1
star
25

M5MidiPlayer

CircuitPython MIDI player app for M5 AtomS3 + Synth Unit
Python
1
star
26

oneliners

An package for enriching your Python programs with random stupid one-liner jokes
Python
1
star