3D Line Spiral Plot
Mix.install([
{:plotly_ex, "~> 0.3"},
{:kino, "~> 0.18"}
])
Section
Setting line.color to a numeric list (same length as x/y/z) + line.colorscale: colors
the line by a variable — here z-position. This creates a gradient spiral showing how the
line progresses through space.
alias Plotly.{Figure, Scatter3d}
n = 300
t = Enum.map(0..(n - 1), &(&1 / (n - 1) * 10 * :math.pi()))
x = Enum.map(t, &:math.cos/1)
y = Enum.map(t, &:math.sin/1)
z = Enum.map(t, & &1)
Figure.new()
|> Figure.add_trace(
Scatter3d.new(
x: x,
y: y,
z: z,
mode: "lines",
line: %{
color: z,
colorscale: "Viridis",
width: 4
}
)
)
|> Figure.update_layout(
title: "3D Line Spiral — Color by Z",
scene: %{
xaxis: %{title: "X"},
yaxis: %{title: "Y"},
zaxis: %{title: "Z"}
}
)
|> Plotly.show()