Basic Parallel Coordinates Plot
Mix.install([
{:plotly_ex, "~> 0.3"},
{:kino, "~> 0.18"}
])
Section
line: %{color: [...], colorscale: "..."} colours each line by a numeric variable.
Provide one colour value per observation (same length as each values list).
A colour bar appears automatically.
alias Plotly.{Figure, Parcoords}
# 8 Iris observations: 0=setosa, 1=versicolor, 2=virginica
species = [0, 0, 0, 0, 0, 1, 1, 2]
Figure.new()
|> Figure.add_trace(
Parcoords.new(
dimensions: [
%{label: "Sepal Length", values: [5.1, 4.9, 4.7, 5.0, 5.4, 6.3, 5.8, 7.1]},
%{label: "Sepal Width", values: [3.5, 3.0, 3.2, 3.6, 3.9, 3.3, 2.7, 3.0]},
%{label: "Petal Length", values: [1.4, 1.4, 1.3, 1.4, 1.7, 4.7, 5.1, 5.9]},
%{label: "Petal Width", values: [0.2, 0.2, 0.2, 0.2, 0.4, 1.6, 1.9, 2.1]}
],
line: %{
color: species,
colorscale: [[0, "purple"], [0.5, "lightseagreen"], [1, "gold"]],
showscale: true,
cmin: 0,
cmax: 2
}
)
)
|> Figure.update_layout(title: "Parallel Coordinates — Coloured by Species")
|> Plotly.show()