14

I have the following Venn diagrams:

from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
set1 = set(['A', 'B', 'C', 'D'])
set2 = set(['B', 'C', 'D', 'E'])
set3 = set(['C', 'D',' E', 'F', 'G'])

venn3([set1, set2, set3], ('Set1', 'Set2', 'Set3'))

That looks like this:

enter image description here

How can I control the font size of the plot? I'd like to increase it.

KT.
  • 10,815
  • 4
  • 47
  • 71
neversaint
  • 60,904
  • 137
  • 310
  • 477

3 Answers3

23

If out is the object returned by venn3(), the text objects are just stored as out.set_labels and out.subset_labels, so you can do:

from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
set1 = set(['A', 'B', 'C', 'D'])
set2 = set(['B', 'C', 'D', 'E'])
set3 = set(['C', 'D',' E', 'F', 'G'])

out = venn3([set1, set2, set3], ('Set1', 'Set2', 'Set3'))
for text in out.set_labels:
    text.set_fontsize(14)
for text in out.subset_labels:
    text.set_fontsize(16)
Marius
  • 58,213
  • 16
  • 107
  • 105
  • 3
    `out.set_labels` works fine, but I get the following error when trying to select `out.subset_labels`: `AttributeError: 'NoneType' object has no attribute 'set_fontsize' ` – Archie Jun 20 '19 at 16:21
4

In my case some values of the out.subset_labels were NoneType. To omit that problem I did:

from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
set1 = set(['A', 'B', 'C', 'D'])
set2 = set(['B', 'C', 'D', 'E'])
set3 = set(['C', 'D',' E', 'F', 'G'])

out = venn3([set1, set2, set3], ('Set1', 'Set2', 'Set3'))
for text in out.set_labels:
    text.set_fontsize(15)
for x in range(len(out.subset_labels)):
    if out.subset_labels[x] is not None:
        out.subset_labels[x].set_fontsize(15)
Ilona
  • 446
  • 4
  • 12
0

I simply changed the font size in Matplotlib (one can also change the text colour using rcParams).

from matplotlib_venn import venn3
from matplotlib import pyplot as plt
plt.figure(figsize = (6, 5))
font1 = {'family':'serif','color':'black','size':16} # use for title
font2 = {'family': 'Comic Sans MS', 'size': 8.5} # use for labels
plt.rc('font', **font2) # sets the default font 
plt.rcParams['text.color'] = 'darkred' # changes default text colour
venn3(subsets=({'A', 'B', 'C', 'D', 'X', 'Y', 'Z'}, 
               {'A', 'B', 'E', 'F', 'P'}, {'B', 'C', 'E', 'G'}), 
      set_labels=('Set1', 'Set2', 'Set3'),
      set_colors=("coral", "skyblue", "lightgreen"), alpha=0.9)

plt.title("Changing Font Size in Matplotlib_venn Diagrams", fontdict=font1)
plt.show()