plot actual set items in python, not the number of items

后端 未结 2 1432
清酒与你
清酒与你 2021-01-15 05:11

I wrote this small function:

def sets():
    set1 = random.sample(range(1, 50), 10)
    set2 = random.sample(range(1, 50), 10)
    return(set1,set2)

sets()
         


        
2条回答
  •  一生所求
    2021-01-15 06:11

    The default behaviour of the venn2 package is to print the size of the overlap of the two sets. Here's the line of the source code where those sizes are added to the Venn diagram plot: https://github.com/konstantint/matplotlib-venn/blob/master/matplotlib_venn/_venn2.py#L247

    To make this print the overlapping numbers you'll have to change the compute_venn2_subsets(a,b) function in this file. Replace the returned argument of compute_venn2_subsets(a,b) with:

    ([val for val in a if val not in b], [val for val in a if val in b], [val for val in b if val not in a])
    

    instead of the set sizes that it's returning right now. If you only want to print the overlapping columns, then make compute_venn2_subsets(a,b) return

    ("", [val for val in a if val in b], "")
    

提交回复
热议问题