YAMVP - Yet Another Matplotlib Venn-diagram Plotter
Project description
YAMVP - Yet Another Matplotlib Venn-diagram Plotter
Overview
This module provides a function for creating Matplotlib figures with ellipse-based Venn diagrams for up to five classes. Its primary aim is a simple interface and visually appealing results.
Features:
- Custom color mixing callbacks.
- Area-proportional option for $n=2$.
Installation
pip install yamvp
Basic Usage
import numpy as np
import matplotlib.pyplot as plt
from yamvp import venn
# Fill a 4D 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)
$n=2$
venn([[None, "B"], ["A", "AB"]], ["Alpha", "Beta"], outfile = "venn2_demo.png")
$n=3$
vals3 = [
[[None, "C"], ["B", "BC"]],
[["A", "AC"], ["AB", "ABC"]],
]
venn(vals3, ["Alpha", "Beta", "Gamma"], outfile = "venn3_demo.png")
$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")
$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")
Additional Color Mixing Options
Average
Each intersection’s 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")
Alpha Stacking
This is what would happen if we simply stacked the ellipses with opacity = 0.5. The result depends 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")
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")
Custom Class Colors
venn(vals3, ["Alpha", "Beta", "Gamma"], colors=["red", "green", "blue"], outfile = "venn3_demo_colors.png")
Area-Proportional Option
For $n = 2$, it is possible to draw the diagram with areas proportional to the given data.
The area_proportional flag is ignored if $n > 2$ or if the input data does not contain positive numbers.
rand2 = np.random.randint(0, 1000, size=(2, 2))
venn(rand2, ["Alpha", "Beta"], area_proportional=True, outfile = "img/rand2_demo.png")
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yamvp-0.3.tar.gz.
File metadata
- Download URL: yamvp-0.3.tar.gz
- Upload date:
- Size: 19.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39956aaea21e2f776e64be83eca260cbfc9b0aa6a07642fac4db67a47cf6669e
|
|
| MD5 |
b28bca453614ce969dca7056db941263
|
|
| BLAKE2b-256 |
70dd890831c905997e19113781b88e981c35ce1ab4e7fe5b3dac1bdfa59da67f
|
File details
Details for the file yamvp-0.3-py3-none-any.whl.
File metadata
- Download URL: yamvp-0.3-py3-none-any.whl
- Upload date:
- Size: 27.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb3b188fd899e9c093e6444222ca5d5011bf3e457a688d72d9895a733216f9a1
|
|
| MD5 |
7f20983084f961eb14424a93488155da
|
|
| BLAKE2b-256 |
62a7276768009957fb71f377ed3b7c9aef83b62c1da889b09c90cdc562f6f7e6
|