konstantint / matplotlib-venn

Area-weighted venn-diagrams for Python/matplotlib
MIT License
496 stars 67 forks source link

Representing the items that don't fall into any of the groups in question #20

Closed jamesdj closed 6 years ago

jamesdj commented 8 years ago

In some contexts, it could be useful to have some way of visualizing, not only what's in set A, set B, and their intersection, but also how many items are in neither set. This is important for understanding whether the size of the intersection is surprisingly large or small. Maybe the Venn diagram as it is now could be set inside a shape, of appropriate relative area, representing the entire space.

konstantint commented 8 years ago

(Just noticed this issue).

I am not sure this kind of functionality should be part of the "core" Venn diagram package, although I will consider now making a "FAQ" in the documentation with snippets solving those problems.

I see two possible ways of depicting the universe. If you only have two sets, then just add a third set denoting the universe:

venn3([set([1,2]), set([2,3]), set([1,2,3,4,5])], ('A', 'B', 'Universe'), ('r', 'g', 'white'))
vc = venn3_circles([set([1,2]), set([2,3]), set([1,2,3,4,5])])
vc[0].set_visible(False)
vc[1].set_visible(False)

If you have three sets, there is currently no easy way to depict the universe in a scale-relevant manner, but at the very least you could add the number, counting the size of the remaining universe to the corner of the diagram. E.g.:

venn2([set([1,2]), set([2,3])])
(x1,x2), (y1,y2) = gca().get_xlim(), gca().get_ylim()
text(x2-0.01, y2-0.01, str(number_of_elements_elsewhere), ha='right', va='top')
gca().add_patch(Rectangle((x1,y1), x2-x1, y2-y1, facecolor='none'))
xlim(x1-0.01, x2+0.01)
ylim(y1-0.01, y2+0.01)
konstantint commented 6 years ago

Duplicate of #32