pythonmatplotlibscipyvenn-diagrammatplotlib-venn

adding a labeled point to a Venn diagram in matplotlib-venn


Say, I am using python and the matplotlib-venn package to create some Venn diagrams. However, I wanted to include a labeled point inside one of the circles. That way I can show that point x is an element of a set A. Is there a way to simply add a point to a diagram in matplotlib-venn?

EDIT: I added a little picture to demonstrate.

enter image description here

Minimal Working Example:

This code will just create the venn diagram but without the point

from matplotlib import pyplot as plt
import numpy as np
from matplotlib_venn import venn2
plt.figure(figsize=(4,4))
v = venn2(subsets = (3, 2, 1))
plt.show()

Solution

  • The Venn diagram is centered at x,y = 0,0. Just plot your point at the desired x,y.

    from matplotlib import pyplot as plt
    from matplotlib_venn import venn2
    plt.figure(figsize=(4,4))
    v = venn2(subsets = (3, 2, 1))
    
    plt.axhline(0, linestyle='--')
    plt.axvline(0, linestyle='--')
    
    plt.plot(-0.5,0.2,'bo')
    plt.text(-0.6,0.2, 'A')
    
    plt.show()