konstantint / matplotlib-venn

Area-weighted venn-diagrams for Python/matplotlib
MIT License
495 stars 67 forks source link

Single circle and label positions #54

Closed shinokada closed 3 years ago

shinokada commented 3 years ago

I am trying to create the following diagram with the matplotlib-venn.

image

I have the following code but as you can see there are some problems.

  1. Is it possible to draw a single Venn-diagram?
  2. lines are not right.
  3. Position of not A: How can I change the position of the label?
  4. How can I add U (universal set)?
%matplotlib inline
from matplotlib_venn import venn2
from matplotlib import pyplot as plt

v = venn2(subsets=(3, 3, 1), set_labels = ('A', "A'"))

# remove numbers
for area in ['01', '10', '11']:
  txt = v.get_label_by_id(area)
  if txt: txt.set_text('')

# changing colors and edge colors  
v.get_patch_by_id('10').set_color('skyblue')
v.get_patch_by_id('10').set_edgecolor('black')
v.get_patch_by_id('11').set_color('skyblue')
v.get_patch_by_id('11').set_edgecolor('skyblue')
v.get_patch_by_id('01').set_color('white')
v.get_patch_by_id('01').set_edgecolor('white')

# changing background
plt.gca().set_axis_on()
plt.gca().set_facecolor('white')
plt.title("Negation", fontsize=30)
ymin, ymax = plt.gca().get_ylim()
plt.ylim(ymin - 0.1, ymax)
plt.show()

image

konstantint commented 3 years ago

I don't think you need matlotlib-venn to plot a single circle. Just draw a circle patch and a rectangle patch along with the needed labels.

shinokada commented 3 years ago

I got up to this so far. Only U is missing. Any idea how to add U outside the box?

import pylab as plt
from matplotlib_venn import venn3, venn3_circles

v = venn3(subsets=(1,1,0,1,0,0,0),set_labels = ('','',''))
# remove numbers
for area in ['01', '10']:
  txt = v.get_label_by_id(area)
  if txt: txt.set_text('')

v.get_patch_by_id('100').set_color('white')
v.get_patch_by_id('001').set_color('white')
v.get_label_by_id('010').set_text('A')
v.get_label_by_id('001').set_text("A'")

# changing background
plt.gca().set_axis_on()
plt.gca().set_facecolor('white')
plt.title("Negation", fontsize=30)
plt.show()

image

shinokada commented 3 years ago

I got it.

I added the following.

plt.text(-1, 0.2, r'U', fontsize=15)

image