Skip to content

daschw/SankeyPlots.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SankeyPlots Build Status

This package provides a Plots.jl recipe for Sankey diagrams.

Installation

julia> ]

pkg> add SankeyPlots

Usage

using SankeyPlots

src = [1, 1, 1, 1, 2, 2, 2, 3, 4, 5]
dst = [6, 3, 7, 4, 3, 7, 4, 7, 8, 8]
weights = [0.1, 0.3, 0.5, 0.5, 0.2, 2.8, 1, 0.45, 4.5, 3.3]

sankey(src, dst, weights)

In addition to Plots.jl attributes the following keyword arguments are supported.

Keyword argument Default value Options
node_labels nothing AbstractVector{<:String}
node_colors nothing Vector of color specifications supported by Plots.jl or color palette
edge_color :gray Plots.jl supported color, color selection from connected nodes with :src, :dst, :gradient, or an AbstractDict{Tuple{Int, Int}, Any} where edge_color[(src, dst)] maps to a color
label_position :inside :legend, :node, :left, :right, :top or :bottom
label_size 8 Int
compact false Bool
force_layer Vector{Pair{Int,Int}}() Vectors of Int pairs specifying the layer for every node e.g. [4=>2] to force node 4 in layer 3
force_order Vector{Pair{Int,Int}}() Vectors of Int pairs specifying the node ordering in each layer e.g. [1=>2] to specify node 1 preceeds node 2 in the same layer
names = [
    "PV",
    "Electricity Buy",
    "Battery",
    "Heat pump",
    "Biomass",
    "Electricity Sell",
    "Electricity Demand",
    "Heat demand",
]
energy_colors = palette(:seaborn_colorblind)[[9, 10, 3, 5, 2, 8, 1, 4]]

sankey(
    src, dst, weights;
    node_labels=names,
    node_colors=energy_colors,
    edge_color=:gradient,
    label_position=:bottom,
    label_size=7,
    compact=true,
    force_layer=[6=>2],
    force_order=[5=>1]
)

Acknowledgement

@oxinabox made this possible by implementing the algorithm that solves the layout in LayeredLayouts.jl.