默认情况下,每次重叠中matplotlib-venn
的venn3
打印计数。我如何打印百分比?
问问题
22 次
1 回答
0
我想到了。只需将每个标签除以总数:
from matplotlib_venn import venn3
subsets = (1, 1, 1, 2, 1, 2, 2)
total = sum(subsets)
venn = venn3(subsets=subsets, set_labels=('Set1', 'Set2', 'Set3'))
for id in [''.join(map(str, i)) for i in product([0, 1], [0, 1], [0, 1])]:
if id == '000':
continue
count = int(venn.get_label_by_id(id).get_text())
venn.get_label_by_id(id).set_text('{:.1%}'.format(count / total))
于 2022-01-31T16:05:38.253 回答