Sankey Diagram in JULIA

How to create Sankey Diagram in JULIA ? Is there any working package completely in Julia ? JuliaHub this is not working properly .

    ~  julia                                                            ✔ 
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.3 (2022-11-14)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(@v1.8) pkg> add Plots
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
  No Changes to `~/.julia/environments/v1.8/Project.toml`
  No Changes to `~/.julia/environments/v1.8/Manifest.toml`

julia> using SankeyPlots

julia> src = [1, 1, 1, 1, 2, 2, 2, 3, 4, 5]
10-element Vector{Int64}:
 1
 1
 1
 1
 2
 2
 2
 3
 4
 5

julia> dst = [6, 3, 7, 4, 3, 7, 4, 7, 8, 8]
10-element Vector{Int64}:
 6
 3
 7
 4
 3
 7
 4
 7
 8
 8

julia> weights = [0.1, 0.3, 0.5, 0.5, 0.2, 2.8, 1, 0.45, 4.5, 3.3]
10-element Vector{Float64}:
 0.1
 0.3
 0.5
 0.5
 0.2
 2.8
 1.0
 0.45
 4.5
 3.3

julia> sankey(src, dst, weights)

julia> names = [
           "PV",
           "Electricity Buy",
           "Battery",
           "Heat pump",
           "Biomass",
           "Electricity Sell",
           "Electricity Demand",
           "Heat demand",
       ]
8-element Vector{String}:
 "PV"
 "Electricity Buy"
 "Battery"
 "Heat pump"
 "Biomass"
 "Electricity Sell"
 "Electricity Demand"
 "Heat demand"

julia> energy_colors = palette(:seaborn_colorblind)[[9, 10, 3, 5, 2, 8, 1, 4]]
ERROR: UndefVarError: palette not defined
Stacktrace:
 [1] top-level scope
   @ REPL[8]:1

julia> 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]
       )
ERROR: UndefVarError: energy_colors not defined
Stacktrace:
 [1] top-level scope
   @ REPL[9]:1

julia> 


Your problem is on this line:

It appears that the palette function is not exported by any of the packages that you’ve loaded, so when you want to call it, it isn’t available. This isn’t your fault - I think something might have changed in the Plots ecosystem since the last update for this package. (I’m no expert, so don’t quote me.)

Perhaps if you add the PlotUtils.jl package, there might be a palette() function in there? Otherwise, I’d recommend that you report a problem on the GitHub repo for SankeyPlots.jl.

Still giving same error.

(@v1.8) pkg> status PlotUtils
Status `~/.julia/environments/v1.8/Project.toml`
  [995b91a9] PlotUtils v1.3.2

You need to import the function from the package too:

import PlotUtils: palette

palette is definitely exported by it.

Seems it was once reexported by Plots, but not anymore. The example needs updating. Like cormullion says, open an issue with SankeyPlots.jl, or better yet, make a PR to fix the documentation if you can.

1 Like

What src , dst and weights means and what values they can take ? There is not much Documentation to understand it all .

As an alternative, you may want to look at ECharts.jl. I rather like the Sankey diagram it produces.

ECharts.jl does not work in Pluto.

ECharts.jl does not work in Pluto. It gives error shown below :sweat_smile:

WebIO not detected.

Please read the troubleshooting guide for more information on how to resolve this issue.

https://juliagizmos.github.io/WebIO.jl/latest/troubleshooting/not-detected/

Please see screenshot below:

I’m guessing - after seeing this PR - that Pluto doesn’t support WebIO now, and won’t in the immediate future.

You could ask the Pluto maintainers about it if you need more details.

1 Like