Skip to main content

A small utility to create stacked waterfalls using matplotlib

Project description

Stacked Waterfalls

Simple utility to plot stacked waterfalls using matplotlib

Drew inspiration from waterfall_ax

Installation

pip install stackedwaterfalls

Simple example

stackedwaterfalls expects a list of list, where each sublist represents a bar, and it's elements represent stacks within that bar. Here's a simple example:

from stackedwaterfalls import StackedWaterfalls as sw

aircomp  =  [[0.74] , [0.16], [0.05, 0.05]]
names = [['N$_2$'], ['O$_2$'], ['AR','H$_2$O']] # Labels of input values

air = sw(aircomp, names)
air.plot()

Simple Example

The colors are automatically picked if nothing is specified in a manner that every subsequent bar has as different a color from the previous as possible based on this great answer here.

Examples on group labels

This example shows how you can do a bunch of things with this:

colors = [['silver'] , ['skyblue'], ['orange', 'royalblue']] 

A = sw(LH2_wind, names, colors)
A.plot(shadecolor = 'green', total = True,
       grouplabel ='Group Label = $\\frac{gas_i}{total}$', 
       barnames = ["Major", "Major", "Oh no!\nToo much Argon"],  
        legkw={'ncol':3,'framealpha':1.0, 'loc':'best', 'fontsize':15}, totalcolor = 'darkred',
       linkskw={'ls':'-.','lw':0.8, 'color':'k', 'alpha':1.0}, grouplabelstyle="]-")

A.ax.set_ylim(0,1.2)

Example

Example on combining graphs

The plotting routine also returns the extent of the x axis that is used so you can use that to add graphs to the right as follows:

names = [['A'], ['B', 'C','D'], ['E', 'F']] # Labels of input values
data_set1 =  [[0.3] , [0.2, 0.0, 0.0], [0.0, 0.030]] 
data_set2 =  [[0.3] , [0.3, 0.0, 0.0], [0.0, 0.030]] 
data_set3 =  [[0.6] , [1e-16  , 0.8, 0.1], [0.01, 1e-16]] #need to set 0's here to very small num that is not zero to force legend elements
colors = [['deepskyblue'], ['royalblue', 'silver','darkorange'], ['brown', 'grey']]

d1 = StackedWaterfalls(data_set1,names, colors)
d2 = StackedWaterfalls(data_set2,names, colors)
d3 = StackedWaterfalls(data_set3,names, colors)

ax, xst2 = d1.plot(shadecolor = 'cornflowerblue',
                   legend=False, linkskw={'lw':'2', 'color':'red', 'alpha':0.1}, total = True, 
                   grouplabel = "Set 1", barnames=["One", "Two", "Three"], grouplabelstyle = ']')
                   
ax, xst3 =  d2.plot(shadecolor = 'yellow', ax = ax, xstart = xst2+0.4, total = True,grouplabel = "Set 2", 
                    grouplabelstyle = "|-",
                    legend=False)
ax, xst4 =  d3.plot(shadecolor = 'red', ax = ax, xstart = xst3+0.4, total = True, grouplabel = "Set 3",
                    grouplabelstyle = "|",
                    legend=True,  legkw={'ncol':3,'framealpha':1.0, 'loc':'best', 'fontsize':15})


ax.grid()
ax.set_ylim(0, 1.8)
plt.tight_layout()

Complex Example

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stackedwaterfalls-0.3.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stackedwaterfalls-0.3.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file stackedwaterfalls-0.3.0.tar.gz.

File metadata

  • Download URL: stackedwaterfalls-0.3.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for stackedwaterfalls-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ce41bc5ac0f5838c16883a18beae7d28004cd7afd15606d35a2c0a2022c88cd3
MD5 ca30b059e4439bcf6bd740804ef7fb7c
BLAKE2b-256 3b67c24d7be3bc9cdbecc693becd54b7ad662e21aea269c0f1aedff0837b8f36

See more details on using hashes here.

File details

Details for the file stackedwaterfalls-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: stackedwaterfalls-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for stackedwaterfalls-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 151733d72892a98fcfbc7a38f582c1694d8a343606959334d02ed3e82abb67ee
MD5 a5d4b1bda511628a8f4b83a6464a470d
BLAKE2b-256 b1f1fbe42a3043b563ac10ac8d64293ffa9219b894e15491e8be13218b427faf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page