Giter Site home page Giter Site logo

pysankey2's Introduction

pySankey2

pySankey2 was developed to draw static Sankey diagrams based on matplotlib.

While the original version of pysankey was developed by anazalea et al. , this version only supports 2-layer Sankey diagrams, and the settable parameters are limited. pySankey2 expands the original version's functions to support multi-layer Sankey diagrams and allows user to set parameters more flexibly.

Installation

  • v0.1.0

pysankey2-v0.1.0 is available at here, you can install locally via pip cmd after downloading:

pip install pysankey2-0.1.0.zip
  • Development version
pip install git+https://github.com/SZJShuffle/pySankey2.git

Usage

Example1:Two-layer

Using a 2-layer demo fruits.txt:

layer1 layer2
blueberry blueberry
apple blueberry
... ...
orange orange

and just with a simple code:

import matplotlib.pyplot as plt
import pandas as pd
from pysankey2.datasets import load_fruits
from pysankey2 import Sankey

df = load_fruits()
sky = Sankey(df,colorMode="global")
fig,ax = sky.plot()

fruits

Setting the strip color to be the same with left box is also allowed:

import matplotlib.pyplot as plt
import pandas as pd
from pysankey2.datasets import load_fruits
from pysankey2.utils import setColorConf
from pysankey2 import Sankey

df = load_fruits()
fruits = list(set(df.layer1).union(set(df.layer2)))

# Specified the colors.
# Here, we use 'Pastel1' colormaps(a shy but fresh palette:)).
# See matplotlib cmap for more colormaps:
# https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html
colors = setColorConf(len(fruits),colors='Pastel1')
cls_map = dict(zip(fruits,colors))

# set stripColor="left" 
sky = Sankey(df,colorDict=cls_map,colorMode="global",stripColor='left')

# set a bigger font size 
fig,ax = sky.plot(text_kws={'size':20})

we get:

fruits2

Example2:Multi-layer

Using a 3-layer demo countrys.txt:

layer1 layer2 layer3
China Canada USA
England China Japan
... ... ...
Senegal Spain USA

and with a simple code:

from pysankey2 import Sankey
from pysankey2.datasets import load_countrys

df = load_countrys()
sky_auto_global_colors = Sankey(df,colorMode="global")
fig,ax = sky_auto_global_colors.plot()

we get:

countrys

Tutorial

For a more detailed tutorial, please refer to:pysankey2_demo

Contact

Any questions, bugs or suggestions are welcome, please feel free to contact: [email protected]

pysankey2's People

Contributors

szjshuffle avatar

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.