使用以下代码:
from matplotlib import pyplot as plt
from matplotlib_venn import venn2
from collections import OrderedDict
named_sets = {'x1': set(['foo','foo','bar',"pax"]), "x3" : set(['foo','qux','bar',"zoo"])}
od = OrderedDict(sorted(named_sets.iteritems()))
circlenm = ()
circlels = []
for k,v in od.iteritems():
circlenm = circlenm + (k,)
circlels.append(v)
c = venn2(subsets = circlels,set_labels = circlenm)
c.get_patch_by_id('10').set_color('red')
c.get_patch_by_id('01').set_color('blue')
c.get_patch_by_id('10').set_edgecolor('none')
c.get_patch_by_id('01').set_edgecolor('none')
c.get_patch_by_id('10').set_alpha(0.4)
c.get_patch_by_id('01').set_alpha(0.4)
plt.show()
我可以得到下图:
我想在这里混合“蓝色'与红色'。 请注意,混合的结果是棕色。
但实际值应为浅洋红色(下图是使用默认matplotlib_venn.venn3
创建的):
我怎样才能正确实现?
答案 0 :(得分:2)
添加这3行以设置交集的颜色和显示属性:
c.get_patch_by_id('11').set_color('magenta')
c.get_patch_by_id('11').set_edgecolor('none')
c.get_patch_by_id('11').set_alpha(0.4)
如果你想要一个确切的颜色,那么你可以像这样设置:
c.get_patch_by_id('11').set_color('#e098e1')
补丁ID是一个位掩码,显示该区域内的圆圈。