使用matplotlib,venn3和venn3_circles在python中工作。

我试图在3个圆的维恩图中获取每个交叉点的元素列表。

我将使用示例here

from matplotlib import pyplot as plt
import numpy as np
from matplotlib_venn import venn3, venn3_circles


A = set(['DPEP1', 'CDC42BPA', 'GNG4', 'RAPGEFL1', 'MYH7B', 'SLC13A3', 'PHACTR3', 'SMPX', 'NELL2', 'PNMAL1', 'KRT23', 'PCP4', 'LOX', 'CDC42BPA'])
B = set(['ABLIM1','CDC42BPA','VSNL1','LOX','PCP4','SLC13A3'])
C = set(['PLCB4', 'VSNL1', 'TOX3', 'VAV3'])

v = venn3([A,B,C], ('GCPromoters', 'OCPromoters', 'GCSuppressors'))

ppp=v.get_label_by_id('100').set_text('\n'.join(A-B-C))
v.get_label_by_id('110').set_text('\n'.join(A&B-C))
v.get_label_by_id('011').set_text('\n'.join(B&C-A))
v.get_label_by_id('001').set_text('\n'.join(C-A-B))
v.get_label_by_id('010').set_text('')
plt.annotate(',\n'.join(B-A-C), xy=v.get_label_by_id('010').get_position() +
             np.array([0, 0.2]), xytext=(-20,40), ha='center',
             textcoords='offset points',
             bbox=dict(boxstyle='round,pad=0.5', fc='gray', alpha=0.1),
             arrowprops=dict(arrowstyle='->',
                             connectionstyle='arc',color='gray'))


在示例中,他们可以在图形维恩图中显示每个交叉点的内容
python - Python:venn3_circles:如何在Venn 3圆图中获取交点的值-LMLPHP

如何在变量/列表中存储每个路口的内容?

我想得到这样的东西:

A:[MYH7B, PHACTR3,...,DPEP1]
AB: [LOX,...,PCP4]
B: [ABLIM1]
ABC: empty
B: empty
BC: [VSNL1]
C: [TOX3,VAV3,PLCB4]


其中A,AB,ABC,C ...是python中的列表

最佳答案

不知道是否一旦创建了维恩图,就可以按照建议提取数据。那将是一个不错的功能,希望该库的某些开发人员会回答。

这样说。您可以做的是利用可以与python sets一起使用的逻辑操作。

Operation   Equivalent  Result
len(s)      number of elements in set s (cardinality)
x in s      test x for membership in s
x not in s      test x for non-membership in s
s.issubset(t)   s <= t  test whether every element in s is in t
s.issuperset(t)     s >= t  test whether every element in t is in s
s.union(t)  s | t   new set with elements from both s and t
s.intersection(t)   s & t   new set with elements common to s and t
s.difference(t)     s - t   new set with elements in s but not in t
s.symmetric_difference(t)   s ^ t   new set with elements in either s or t but not both
s.copy()        new set with a shallow copy of s


例如,要获取AB,ABC等,您可以执行以下操作:

AB = A.intersection(B).difference(C)

ABC = A.intersection(B).intersection(C)


希望这会有所帮助!

10-07 19:00
查看更多