Adding Names to Line and Scatter Plot
Mix.install([
{:plotly_ex, "~> 0.3"},
{:kino, "~> 0.18"}
])
Section
Set name: on each trace to control what appears in the legend. Without
names, Plotly uses "trace 0", "trace 1", etc.
alias Plotly.{Figure, Scatter}
Figure.new()
|> Figure.add_trace(
Scatter.new(
x: [1, 2, 3, 4],
y: [10, 15, 13, 17],
mode: "markers",
name: "Scatter"
)
)
|> Figure.add_trace(
Scatter.new(
x: [2, 3, 4, 5],
y: [16, 5, 11, 9],
mode: "lines",
name: "Lines"
)
)
|> Figure.add_trace(
Scatter.new(
x: [1, 2, 3, 4],
y: [12, 9, 15, 12],
mode: "lines+markers",
name: "Lines and Markers"
)
)
|> Figure.update_layout(title: "Named Traces")
|> Plotly.show()