Powered by AppSignal & Oban Pro

Add Nodes

60_add_nodes.livemd

Add Nodes

Mix.install([
  {:plotly_ex, "~> 0.3"},
  {:kino, "~> 0.18"}
])

Section

Style nodes via node.color, node.pad (spacing between nodes), node.thickness, and node.line (border around each node block).

alias Plotly.{Figure, Sankey}

Figure.new()
|> Figure.add_trace(
  Sankey.new(
    node: %{
      label: ["Coal", "Natural Gas", "Oil", "Electricity", "Losses"],
      color: ["black", "blue", "brown", "gold", "gray"],
      pad: 20,
      thickness: 30,
      line: %{color: "black", width: 0.5}
    },
    link: %{
      source: [0, 1, 2, 0, 1],
      target: [3, 3, 3, 4, 4],
      value:  [25, 20, 30, 10, 15]
    }
  )
)
|> Figure.update_layout(title: "Sankey — Styled Nodes", width: 800, height: 500)
|> Plotly.show()