vinsburg / alluvial_diagram

A python script for generating "alluvial" styled bipartite diagrams, using matplotlib and numpy
GNU General Public License v3.0
47 stars 11 forks source link

alluvial_diagram

A python script for generating "alluvial" styled bipartite diagrams, using matplotlib and numpy

Getting Started

Copy alluvial.py to a directory on the path, and import alluvial as shown below.

Prerequisites

pip install -r requirements.txt

Setup

Place alluvial.py on path.

Example 1:


import alluvial
import matplotlib.pyplot as plt
import numpy as np

input_data = {'a': {'aa': 0.3, 'cc': 0.7,},
              'b': {'aa': 2, 'bb': 0.5,},
              'c': {'aa': 0.5, 'bb': 0.5, 'cc': 1.5,}}

ax = alluvial.plot(input_data)
fig = ax.get_figure()
fig.set_size_inches(5,5)
plt.show()

Example 2:


import alluvial
import matplotlib.pyplot as plt
from matplotlib import colormaps 
import numpy as np

# Generating the input_data:
seed=7
np.random.seed(seed)
def rand_letter(num): return chr(ord('A')+int(num*np.random.rand()))

input_data = [[rand_letter(15), rand_letter(5)*2] for _ in range(50)]

# Plotting:
cmap = colormaps['jet']
ax = alluvial.plot(
    input_data,  alpha=0.4, color_side=1, rand_seed=seed, figsize=(7,5),
    disp_width=True, wdisp_sep=' '*2, cmap=cmap, fontname='Monospace',
    labels=('Capitals', 'Double Capitals'), label_shift=2)
ax.set_title('Utility display', fontsize=14, fontname='Monospace')
plt.show()

Parameter overview

License

This project is licensed under the Apache 2.0 License - see the LICENSE.md file for details

Acknowledgments