# Sankey Diagram in JULIA

**URL:** <https://discourse.julialang.org/t/sankey-diagram-in-julia/92884>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [January 12, 2023, 5:19pm UTC](https://discourse.julialang.org/t/sankey-diagram-in-julia/92884 "2023-01-12T17:19:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [January 12, 2023, 5:19pm UTC](https://discourse.julialang.org/t/sankey-diagram-in-julia/92884/1 "2023-01-12T17:19:51Z")

</div>

How to create Sankey Diagram in JULIA ? Is there any working package completely in Julia ? [JuliaHub](https://juliahub.com/ui/Packages/SankeyPlots/wbeai/0.2.2?page=0) this is not working properly .

```julia
    ~  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> 

```

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [January 12, 2023, 6:40pm UTC](https://discourse.julialang.org/t/sankey-diagram-in-julia/92884/2 "2023-01-12T18:40:29Z")

</div>

Your problem is on this line:

> [@raman\_kumar](#):
>
> ```julia
> energy_colors = palette(:seaborn_colorblind)[[9, 10, 3, 5, 2, 8, 1, 4]]
> ERROR: UndefVarError: palette not defined
> 
> ```

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.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [January 13, 2023, 5:23am UTC](https://discourse.julialang.org/t/sankey-diagram-in-julia/92884/3 "2023-01-13T05:23:57Z")

</div>

Still giving same error.

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

```

---

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [January 13, 2023, 5:54am UTC](https://discourse.julialang.org/t/sankey-diagram-in-julia/92884/4 "2023-01-13T05:54:24Z")

</div>

You need to import the function from the package too:

```julia
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.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [January 13, 2023, 9:12am UTC](https://discourse.julialang.org/t/sankey-diagram-in-julia/92884/5 "2023-01-13T09:12:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![braamvandyk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/braamvandyk/32/5086_2.png) [@braamvandyk](https://discourse.julialang.org/u/braamvandyk)\
**Post date:** [January 13, 2023, 10:48am UTC](https://discourse.julialang.org/t/sankey-diagram-in-julia/92884/6 "2023-01-13T10:48:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [January 14, 2023, 9:04am UTC](https://discourse.julialang.org/t/sankey-diagram-in-julia/92884/7 "2023-01-14T09:04:26Z")

</div>

ECharts.jl does not work in Pluto.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [January 15, 2023, 9:19am UTC](https://discourse.julialang.org/t/sankey-diagram-in-julia/92884/8 "2023-01-15T09:19:02Z")

</div>

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

**WebIO not detected.**

Please read [the troubleshooting guide](https://juliagizmos.github.io/WebIO.jl/latest/troubleshooting/not-detected/) for more information on how to resolve this issue.

[https://juliagizmos.github.io/WebIO.jl/latest/troubleshooting/not-detected/](https://juliagizmos.github.io/WebIO.jl/latest/troubleshooting/not-detected/)

Please see screenshot below:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/2/92fdc49063eb16ca180cc988fa8e3bd3c4544ce0.png)

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [January 15, 2023, 10:10am UTC](https://discourse.julialang.org/t/sankey-diagram-in-julia/92884/9 "2023-01-15T10:10:34Z")

</div>

I’m guessing - after seeing [this PR](https://github.com/fonsp/Pluto.jl/pull/2392) - 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.
