Giter Site home page Giter Site logo

lankycyril / pyvenn Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tctianchi/pyvenn

118.0 5.0 27.0 2.23 MB

Python module for plotting Venn diagrams of 2..6 sets

Home Page: https://pypi.org/project/venn

License: GNU General Public License v3.0

Python 3.86% Jupyter Notebook 96.14%
visualization data-science matplotlib matplotlib-venn venn-diagram venndiagram venn

pyvenn's Introduction

pyvenn: Venn diagrams for 2, 3, 4, 5, 6 sets

Please refer to the Jupyter notebook for demos and a brief explanation of the interface; a more complete documentation is in the works as the project keeps evolving:
https://github.com/LankyCyril/pyvenn/blob/master/pyvenn-demo.ipynb

This library is an evolution of tctianchi's pyvenn package (see fork URL).
Their liberal license (Unlicense) allowed me to fork the repository, change the license to GPLv3, modify the package's interface and, hopefully, significantly contribute to and improve the library, and make it installable from PyPI.

The main methods in this version are different from the ones in tctianchi's implementation, but the original methods are still provided for backwards compatibility, and I would like to emphasize the importance of tctianchi's work that allowed for this library to exist (among other things, figuring out the coordinates best fit for plotting the diagrams' shapes and petals' labels).

This iteration of the library implements two main functions:

  • venn(dataset_dict, **kwargs) which plots true Venn diagrams for any number of sets between 2 and 5 using ellipses, and for 6 sets using triangles
  • pseudovenn(dataset_dict, **kwargs) which plots a Venn-like intersection of six circles (not all intersections are present in such a plot, but many are).

pyvenn's People

Contributors

josephryanpeterson avatar lankycyril avatar tctianchi avatar tyberiusprime avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pyvenn's Issues

Error message

Trying to run this in PyCharm. Says "NameError: name 'venn' is not defined." All packages seem to be installed. Also, I am new at python so I am unsure of some things, but how can I run my own data in this code?

Changing Graph SIze

When resizing with figsize, the image itself does not get larger than a certain amount, only the whitespace around it.

Is it possible to increase the image size without compromising the resolution? Generating labels for the petals gets squishy when more information is needed.

ax.get_legend_handles_labels() returns emtpy lists

I'd like to change the number of columns in the legend so that there is only one row (ncol = number of groups).

To do so I thought I could take the ax returned from venn and use the method .get_legend_handles_labels() which I could pass to ax.legend to also specify ncol. However, ax.get_legend_handles_labels() returns two empty lists, which when passed to ax.legend cause the legend to disappear.

musicians = {
    "Members of The Beatles": {"Paul McCartney", "John Lennon", "George Harrison", "Ringo Starr"},
    "Guitarists": {"John Lennon", "George Harrison", "Jimi Hendrix", "Eric Clapton", "Carlos Santana"},
    "Played at Woodstock": {"Jimi Hendrix", "Carlos Santana", "Keith Moon"}
}
ax = venn(musicians)
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels, ncol=3)

Screen Shot 2021-11-26 at 11 26 06 AM

The potential work-around is to just pass the keys of the dictionary musicians to ax.legend and also specify ncol (this produces a figure as expected), but still not sure why ax.get_legend_handles_labels() doesn't work.

sizing

Loving how much more user friendly your package is over the alternatives!

Is there a way to make the size of the circles (at least for 2 and 3 comparisons) based on the size of the sets?

pyvenn with matplolib subplots

Hello.
Recently I was trying to plot a Venn diagram in a matplotlib subplot but it always goes out of the plot. Is there a way to insert it back?

non-interactive/batch example to image file?

Can you create or describe an example that produces an image file? I'd like to leverage your work to quickly produce diagrams, but I'm not a matplot user, and I don't see where any file is written out.

For context, I tried:

pip3 install --user venn 
grep -v '^%' your-minimal-musician-example | tee musician.py
  from venn import venn

 musicians = {
     "Members of The Beatles": {"Paul McCartney", "John Lennon", "George Harrison", "Ringo Starr"},
     "Guitarists": {"John Lennon", "George Harrison", "Jimi Hendrix", "Eric Clapton", "Carlos Santana"},
     "Played at Woodstock": {"Jimi Hendrix", "Carlos Santana", "Keith Moon"}
  }
  venn(musicians)

python3 musician.py

The file runs once the %matplotlib inline is removed, but the result doesn't export the generated object as an image. Perhaps it's trying to manipulate a running matplot process?

Venn() does not generate image

I follow the minimal example in the description page, but when I run the module (IDLE), though it throws no error, it does not generate any image.

Export counted values in petals

Hi,

pyvenn is very useful but for my use it lacks an export function of information on the groups in each petal.
The code below is a suggestion for this type of function. It exports the results as a table (dataframe).
You can improve it, if you don't want to use pandas.

import pandas as pd
from venn import *

def generate_logics(n_sets):
    """Generate intersection identifiers in binary (0010 etc)"""
    for i in range(1, 2**n_sets):
        yield bin(i)[2:].zfill(n_sets)
        
def generate_group_labels(datasets, fmt="{size}"):
    """Generate petal descriptions for venn diagram based on set sizes"""
    datasets = list(datasets)
    n_sets = len(datasets)
    dataset_union = set.union(*datasets)
    universe_size = len(dataset_union)
    petal_labels = {}
    petal_set2 = {}
    for logic in generate_logics(n_sets):
        included_sets = [
            datasets[i] for i in range(n_sets) if logic[i] == "1"
        ]
        excluded_sets = [
            datasets[i] for i in range(n_sets) if logic[i] == "0"
        ]
        petal_set = (
            (dataset_union & set.intersection(*included_sets)) -
            set.union(set(), *excluded_sets)
        )
        petal_labels[logic] = fmt.format(
            logic=logic, size=len(petal_set),
            percentage=(100*len(petal_set)/max(universe_size, 1))
        )
        petal_set2[logic] = fmt.format(
            logic=logic, size = (dataset_union & set.intersection(*included_sets)) -
            set.union(set(), *excluded_sets)
        )
        labelset = pd.DataFrame(petal_labels.items())
        grpset = pd.DataFrame(petal_set2.items())
        dfset = labelset.merge(grpset, on = 0)
        dfset.columns= ["Comparison", "Count", "Groups"]
    
    return dfset

Example:

groupset = {
    "Cells 1": {'RBM15', 'FAM76B', 'TNIK', 'TUSC3', 'ZFYVE27'},
    "Cells 2": {'RBM15', 'TMEM8A', 'ARRDC2', 'TUSC3', 'ZFYVE27'},
    "Cells 3": {'ARRDC2', 'UNC50', 'TNIK', 'TUSC3', 'TMEM8A'},
    "Cells 4": {'RBM15', 'UNC50', 'TNIK', 'TUSC3'}
}

dfset = generate_group_labels(groupset.values())
dfset

Output:

Comparison Count Groups
0001 0 set()
0010 0 set()
0011 1 {'UNC50'}
0100 0 set()
0101 0 set()
0110 2 {'TMEM8A', 'ARRDC2'}
0111 0 set()
1000 1 {'FAM76B'}
1001 0 set()
1010 0 set()
1011 1 {'TNIK'}
1100 1 {'ZFYVE27'}
1101 1 {'RBM15'}
1110 0 set()
1111 1 {'TUSC3'}

Best regards,

JR

Documentation on Changing Colors

I'm trying to figure out a way to specify specific color mappings. I've put a list of rgb colors into a 2D list but it's failing to take the 2D list and parse it.

Is there another way to specify colors. I have to use specific colors for work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.