def compute_venn3_areas(diagram_areas, normalize_to=1.0, _minimal_area=1e-6):
'''
The list of venn areas is given as 7 values, corresponding to venn diagram areas in the following order:
(Abc, aBc, ABc, abC, AbC, aBC, ABC)
(i.e. last element corresponds to the size of intersection A&B&C).
The return value is a list of areas (A_a, A_b, A_c, A_ab, A_bc, A_ac, A_abc),
such that the total area of all circles is normalized to normalize_to.
If the area of any circle is smaller than _minimal_area, makes it equal to _minimal_area.
Assumes all input values are nonnegative (to be more precise, all areas are passed through and abs() function)
>>> compute_venn3_areas((1, 1, 0, 1, 0, 0, 0))
(0.33..., 0.33..., 0.33..., 0.0, 0.0, 0.0, 0.0)
>>> compute_venn3_areas((0, 0, 0, 0, 0, 0, 0))
(1e-06, 1e-06, 1e-06, 0.0, 0.0, 0.0, 0.0)
>>> compute_venn3_areas((1, 1, 1, 1, 1, 1, 1), normalize_to=7)
(4.0, 4.0, 4.0, 2.0, 2.0, 2.0, 1.0)
>>> compute_venn3_areas((1, 2, 3, 4, 5, 6, 7), normalize_to=56/2)
(16.0, 18.0, 22.0, 10.0, 13.0, 12.0, 7.0)
'''
# Normalize input values to sum to 1
areas = np.array(np.abs(diagram_areas), float)
total_area = np.sum(areas)
if np.abs(total_area) < _minimal_area:
warnings.warn("All circles have zero area")
return (1e-06, 1e-06, 1e-06, 0.0, 0.0, 0.0, 0.0)
else:
areas = areas / total_area * normalize_to
A_a = areas[0] + areas[2] + areas[4] + areas[6]
if A_a < _minimal_area:
warnings.warn("Circle A has zero area")
A_a = _minimal_area
A_b = areas[1] + areas[2] + areas[5] + areas[6]
if A_b < _minimal_area:
warnings.warn("Circle B has zero area")
A_b = _minimal_area
A_c = areas[3] + areas[4] + areas[5] + areas[6]
if A_c < _minimal_area:
warnings.warn("Circle C has zero area")
A_c = _minimal_area
# Areas of the three intersections (ab, ac, bc)
A_ab, A_ac, A_bc = areas[2] + areas[6], areas[4] + areas[6], areas[5] + areas[6]
return (A_a, A_b, A_c, A_ab, A_bc, A_ac, areas[6])
评论列表
文章目录