enter code here--我正在尝试使用matplotlib_venn创建venn图。venn2和venn2_circle的结合会产生带有边框的漂亮图。现在,试图使用venn2_unweighted制作未加权版本,但没有找到venn2_unweighted_circle或任何替代方法来设置边框。有什么帮助吗?
from matplotlib_venn import venn2, venn2_circles, venn2_unweighted
def compare_items(items1, items2, labels = ['Set A', 'Set B'], venn = False,title='',colors=None,
border=True, fill=True, unweighted = True):
list1 = set(items1)
list2 = set(items2)
common = list(list1.intersection(list2))
list1_only = list1.difference(common)
list2_only = list2.difference(common)
subsets = (len(list1_only), len(list2_only), len(common))
print('{label1} = {count1} \t {label2} = {count2}\t Common = {count_com}'.format(
label1 =labels[0],count1 = len(list1), label2 = labels[1], count2 =len(list2),count_com = len(common)))
if venn:
fig = plt.figure(figsize=(8,6))
color_used = colors if colors else ("orange", "lightblue")
if fill:
if unweighted:
venn2_unweighted(subsets=subsets, set_labels=labels, set_colors=color_used, alpha=0.7,ax=plt.gca())
else:
venn2(subsets=subsets, set_labels=labels, set_colors=color_used, alpha=0.7,ax=plt.gca())
if border:
border_color = ['#ffffff']*2
if unweighted:
venn2_unweighted_circles(subsets=subsets,ax=plt.gca())
else:
circles = venn2_circles(subsets=subsets,ax=plt.gca())
for circle, color in zip(circles, border_color):
circle.set_lw(2.0)
circle.set_ls('solid')
circle.set_alpha(1)
circle.set_edgecolor(color)
plt.gca().set_title(title)发布于 2022-08-08 11:12:24
虽然venn2_unweighted_circles不存在,但您可以简单地使用带有子集= (1,1,1)的venn2_circles。
import matplotlib.pyplot as plt
from matplotlib_venn import venn2_unweighted
from matplotlib_venn import venn2_circles
v = venn2_unweighted(subsets = (12, 54, 938), set_labels = ('Set1', 'Set2'))
c = venn2_circles(subsets = (1, 1, 1))或者,您可以在子集= (1,1,1)中使用venn2,但是将文本标签更改为要显示的数字:
v = venn2(subsets = (1, 1, 1), set_labels = ('Set1', 'Set2'))
v.get_label_by_id("10").set_text("12")
v.get_label_by_id("01").set_text("54")
v.get_label_by_id("11").set_text("938")
c = venn2_circles(subsets = (1, 1, 1))https://stackoverflow.com/questions/71506064
复制相似问题