在每组中打印实际的随机数,而不是重叠的数字

时间:2019-08-30 23:00:02

标签: python matplotlib

如果运行此代码,则可以打印两个重叠的组,并在组的每个部分中显示实际字母:

import matplotlib
import matplotlib.backends.backend_tkagg
from matplotlib import pyplot as plt
import matplotlib.style
from matplotlib_venn import venn2
from matplotlib_venn import venn3
string_str = 'abcdefghijklmnopqrstuvwxyz'
set1 = set(random.sample(string_str,10))
set2 = set(random.sample(string_str,10))
venn = venn2([set1,set2],('Group 1', 'Group 2'))
venn.get_label_by_id('100').set_text('\n'.join(map(str,set1-set2)))
venn.get_label_by_id('110').set_text('\n'.join(map(str,set1&set2)))
venn.get_label_by_id('010').set_text('\n'.join(map(str,set2-set1)))
plt.axis('on')
plt.show()

输出:

我实际上想执行相同的输出,但是(1)使用三组而不是2组,以及(2)使用数字而不是字母。

我写了这段代码:

numbers_set1 = set(random.sample(list(range(1,9)),5))
numbers_set2 = set(random.sample(list(range(1,9)),5))
numbers_set3 = set(random.sample(list(range(1,9)),5))
venn3([numbers_set1, numbers_set2, numbers_set3], ('Set1', 'Set2', 'Set3'))
plt.axis('on')
plt.show() 

输出几乎正确:

如何编辑此代码以打印每组中的实际数字?

0 个答案:

没有答案