如何在matplotlib-venn中修改字体大小

nev*_*int 7 python matplotlib venn-diagram matplotlib-venn

我有以下维恩图:

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'))
Run Code Online (Sandbox Code Playgroud)

看起来像这样:

在此输入图像描述

如何控制绘图的字体大小?我想增加它.

Mar*_*ius 14

如果out是返回的对象venn3(),则文本对象仅作为out.set_labels和存储out.subset_labels,因此您可以执行以下操作:

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)
Run Code Online (Sandbox Code Playgroud)

  • `out.set_labels` 工作正常,但在尝试选择 `out.subset_labels` 时出现以下错误:`AttributeError: 'NoneType' object has no attribute 'set_fontsize' ` (3认同)

Ilo*_*ona 5

就我而言,out.subset_labels 的某些值是 NoneType。为了忽略这个问题,我做了:

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)
Run Code Online (Sandbox Code Playgroud)