2

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()
KT.
  • 10,815
  • 4
  • 47
  • 71
krishnab
  • 9,270
  • 12
  • 66
  • 123
  • Do you have a [MCVE](http://stackoverflow.com/help/mcve) that you can share? – Ffisegydd Jun 17 '14 at 08:34
  • Added a MCVE as requested. – krishnab Jun 17 '14 at 09:05
  • Oh sorry. I get what you mean now. Yes, I can do that. – krishnab Jun 17 '14 at 09:08
  • Yeah I understand, but if you could provide the code to create just the Venn diagrams (without the point) then that means that someone who wishes to help you doesn't have to create the Venn diagrams themselves. They can take your existing code and simply add the code for adding a point. – Ffisegydd Jun 17 '14 at 09:09

1 Answers1

2

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()
rapelpy
  • 1,684
  • 1
  • 11
  • 14
  • Is there a way to do this automatically -- without specifying each point? I have as many as 50 elements I'd like to place in the diagram. – zadrozny Jul 13 '16 at 14:15
  • 2
    @zadrozny Put the two in a loop, e.g. `[plt.plot((x,y),'bo') for (x,y) in list_of_coords]`, and the same for the labels? – jtlz2 Aug 02 '17 at 06:41