konstantint / matplotlib-venn

Area-weighted venn-diagrams for Python/matplotlib
MIT License
508 stars 68 forks source link

there's space at 3 intersections #40

Closed Coaxecva closed 6 years ago

Coaxecva commented 6 years ago

Hi Konstantin,

I tried to plot venn3:

plot_venn_3_groups([3*10**6, 3*10**6, 2*10**4, 4*10**6, 3*10**5, 2*10**4, 4*10**3])

and it happened that the middle intersection between 3 sets has a space (4000). I think it is because of the high different ratios between sets. Can you help me fix this?

test

Thanks! Quang

konstantint commented 6 years ago

The default circle layout algorithm is made so that circle pairwise intersection areas are "to scale". The diagram does not have sufficient number of degrees of freedom to guarantee the appropriate scale of the central part as well, hence in various pathological cases you may find yourself in the situation like the one above.

The only way to overcome it at the moment is to manually tune the central part's area to be larger than it "wants" to be according to your data. There is a utility function venn3_unweighted which lets you do it:

from matplotlib_venn import venn3, venn3_unweighted
venn3_unweighted([3*10**6, 3*10**6, 2*10**4, 4*10**6, 3*10**5, 2*10**4, 4*10**3], 
                subset_areas=[3*10**6, 3*10**6, 2*10**4, 4*10**6, 3*10**5, 2*10**4, 4*10**5])

Here the first parameter is only specifying the numbers shown on the circles, and if you do not specify subset_areas you will get an "unweighted" diagram (with the "area vector" equal to [1,1,1,1,1,1,1]).

The subset_areas, however, lets you specify a custom area vector and, as you see, providing the same numbers except for the increased last number (which corresponds to the "central area") kind-of solves the problem.

There is a dangling task here for developing other layout methods besides the available "naive" one, but so far I've never found the time for it and neither does there seem to be a pressing demand for it anyway.

Coaxecva commented 6 years ago

Thanks! I fixed the graph with `venn3_unweighted: test