Skip to main content

YAMVP - Yet Another Matplotlib Venn-diagram Plotter

Project description

Python 3x pypi

YAMVP - Yet Another Matplotlib Venn-diagram Plotter

Overview

This module provides a function to create Matplotlib figures containing ellipse-based Venn-diagrams with up to 5 classes.

The main goal was to provide a simple interface and good looks.

For example, color mixing of the class intersections does not simply rely on alpha stacking.

Installation

pip install yamvp

Basic Usage

from yamvp import venn
import numpy as np

#Fill a 4-dim 2x2x2x2 array with random values
rand4 = np.random.randint(0, 1000, size=(2, 2, 2, 2))
    
#Set the value at A∩B to 42
rand4[1,1,0,0] = 42

#Create the Venn-diagram
fig = venn(rand4, ["A", "B", "C", "D"])

#save the figure
fig.savefig("rand4_demo.png", dpi=100, bbox_inches="tight")
plt.close(fig)

rand4_demo

n=1

venn([None, "A"], ["Alpha"], outfile = "venn1_demo.png")

venn1_demo

n=2

venn([[None, "B"], ["A", "AB"]], ["Alpha", "Beta"], outfile = "venn2_demo.png")

venn2_demo

n=3

vals3 = [
    [[None, "C"], ["B", "BC"]],
    [["A", "AC"], ["AB", "ABC"]],
]
venn(vals3, ["Alpha", "Beta", "Gamma"], outfile = "venn3_demo.png")

venn3_demo

n=4

vals4 = np.empty((2, 2, 2, 2), dtype=object)
for i, yA in enumerate(("", "A")):
    for j, yB in enumerate(("", "B")):
        for k, yC in enumerate(("", "C")):
            for l, yD in enumerate(("", "D")):
                vals4[i, j, k, l] = yA + yB + yC + yD
vals4[0,0,0,0] = None

venn(vals4, ["Alpha", "Beta", "Gamma", "Delta"], outfile = "venn4_demo.png")

venn4_demo

n=5

vals5 = np.empty((2, 2, 2, 2, 2), dtype=object)
for i, yA in enumerate(("", "A")):
    for j, yB in enumerate(("", "B")):
        for k, yC in enumerate(("", "C")):
            for l, yD in enumerate(("", "D")):
                for m, yE in enumerate(("", "E")):
                    vals5[i, j, k, l, m] = yA + yB + yC + yD + yE
vals5[0,0,0,0,0] = None

venn(vals5, ["Alpha", "Beta", "Gamma", "Delta", "Epsilon"], outfile = "venn5_demo.png")

venn5_demo

Additional Color Mixing Options

Average

Each intersection color is the mean of the corresponding class colors.

venn(vals4, ["Alpha", "Beta", "Gamma", "Delta"], color_mixing = "average", outfile="venn4_demo_colors_average_mixing.png")

venn4_demo_colors_average_mixing

Alpha Stacking

This would happen, if we simply stacked the ellipses with opacity=0.5. The result is dependent on the order in which the ellipses are drawn.

venn(vals4, ["Alpha", "Beta", "Gamma", "Delta"], color_mixing = "alpha", outfile = "venn4_demo_colors_alpha_mixing.png")      

venn4_demo_colors_alpha_mixing

Custom Mixing Callback

def color_mix_multiply(colors):
    arr = np.stack([np.array(c, float) for c in colors], axis=0)
    return np.prod(arr, axis=0)

venn(vals4, ["Alpha", "Beta", "Gamma", "Delta"], color_mixing=color_mix_multiply, outfile="venn4_demo_colors_multiply_mixing.png", text_color="white")     

venn4_demo_colors_multiply_mixing

Custom Class Colors

venn(vals3, ["Alpha", "Beta", "Gamma"], colors=["red", "green", "blue"], outfile = "venn3_demo_colors.png")

venn3_demo_colors

License

This project is licensed under the MIT License (c) 2025 Bálint Csanády, aielte-research. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yamvp-0.2.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yamvp-0.2-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file yamvp-0.2.tar.gz.

File metadata

  • Download URL: yamvp-0.2.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for yamvp-0.2.tar.gz
Algorithm Hash digest
SHA256 0ac951352427eda99db1b555ba56e85b7b870817fa4a5b85a43ccaaf5bd20214
MD5 758895ca6212aba2ec8bbf5b0bc99471
BLAKE2b-256 1a207d3a3a68b7c2c2fc018f61793403bd3b593af1632937661903ae2f661557

See more details on using hashes here.

File details

Details for the file yamvp-0.2-py3-none-any.whl.

File metadata

  • Download URL: yamvp-0.2-py3-none-any.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for yamvp-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fec025e3316092defc3d6ffdfa6cda8d87a53479af55b3dcae0bf1fdeb2b56e2
MD5 9bd3c9e8686fd4e548fd116bcf0ddf49
BLAKE2b-256 7edc37f0b67248145404c0ba2e169b2b0a1a4d937ae58faf2be3367d5b4435b6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page