python - Matplotlib-Venn 中准确的颜色混合

标签 python matplotlib venn-diagram matplotlib-venn

使用以下代码:

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()

我可以得到下图:

enter image description here

在这里,我想将“蓝色”圆圈与“红色”圆圈混合。 请注意,混合的结果是棕色

但实际值应该是light magenta(下图是使用默认matplotlib_venn.venn3创建的):

enter image description here

我怎样才能正确地做到这一点?

最佳答案

添加这 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 是一个位掩码,显示该区域位于哪个圆圈内。

关于python - Matplotlib-Venn 中准确的颜色混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29763360/

相关文章:

python - Numpy - 列之间的平均距离

python - 如何在保持区分大小写的同时消除 Python 中的重复列表条目?

python - 在matplotlib的 basemap 中设置经度和纬度线的线条样式?

algorithm - 有什么比蛮力更好的算法来分离重叠类别中的项目?

r - 在 R 中注释维恩图

python - 如何在 Python 中计算干湿拼写?

python - 如何从 html 内容中删除 "&nbsp"?

python - 如何在 Bokeh (Python) 中处理图像

python - 无法在 Mac OS X 10.6 上的 Python 中的 Matplotlib 中将字体更改为 Helvetica

r - 半透明的维恩图比例和颜色着色