Accurate color mixing in Matplotlib-Venn
With the following code:
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()
I can get the following figure:
Here I would like to combine the "blue" circles with the "red" ones. Note that the mixing result is brown .
But the actual value should be light magenta (the picture below is generated by default matplotlib_venn.venn3
):
How can I achieve this correctly?
+3
source to share
1 answer
Add these 3 lines to set the color and display properties of the intersection:
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)
If you want an exact color, you can set the following:
c.get_patch_by_id('11').set_color('#e098e1')
The patch identifier is a bit mask showing which circles are inside.
+2
source to share