tctianchi / pyvenn

2 ~ 6 sets venn diagram for python
The Unlicense
316 stars 119 forks source link

Support for label combination 00... #7

Open nhartwic opened 5 years ago

nhartwic commented 5 years ago

I'm sure there is probably a way to do it using some combination of pyplot commands, but given this comes up quite a bit for venn diagrams, it would be nice if there was a clean way to specify labels and counts for the null-combination of classes. For example, the venn2 function should be able to cleanly handle input like...

labels = {"00": 2, "01": 5, "10": 5, "11": 10}
fig, ax = venn.venn2(labels, names=['list 1', 'list 2'])

and it should document the fact that their are 2 data points that aren't in list 1 or list 2 somewhere on the resultant figure. For now my easiest sollution to this is to just use pyplot.text and manually create the label for the category, but this is clunky. Another arguably less clunky sollution is to create the null category as a new label type and do something like...

labels = {"001": 2, "010": 5, "100": 5, "110": 10}
fig, ax = venn.venn3(labels, names=['list 1', 'list 2', "neither"])

I don't like this sollution though as it adds a false dimension to the data creating lots of positions where it seems like a count should exist but doesn't. ("111" for example)

The ideal sollution would both add the label for the 00* category to the legend and provide the ability to label the whitespace with the relevant count and name. This would probably require adding a keyword argument to the vennK functions to make them into something like.

def venn2(labels, names=['A', 'B'], null_name="None", **options):

EDIT: Played with it some more. Here is a way to add "null" labels to venn diagrams at the moment for anyone reading this. Would be nice if something like this became default behavior though or could easily be done through the use of an optional argument like "null_name" above

# names = some list of label names
# labels = dict mapping label combinations to counts as usual
fig, ax = venn2(labels, names)

# remake legend with null label
ax.plot([], color="white")
legend_null_label = "neither : 2"
ax.legend( [legend_null_label] + names, loc='center left', bbox_to_anchor=(1.0, 0.5), fancybox=True)

# optionally add the information somewhere on the figure
ax.text(0.95, 0.4, legend_null_label)
osp-ng commented 5 years ago

This issue asks to add a "complement set" to Venn diagrams.

Check wikipedia

Please send your pull request.