Powered by AppSignal & Oban Pro

Hiding Legend Entries

94_hiding_legend_entries.livemd

Hiding Legend Entries

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

Section

Set showlegend: false on a specific trace to hide its entry from the legend while keeping the trace visible in the chart.

alias Plotly.{Figure, Scatter}

Figure.new()
|> Figure.add_trace(Scatter.new(x: [1, 2, 3], y: [2, 4, 3], name: "Visible", mode: "lines"))
|> Figure.add_trace(
  Scatter.new(
    x: [1, 2, 3],
    y: [1, 2, 1],
    name: "Hidden from Legend",
    mode: "lines",
    showlegend: false
  )
)
|> Figure.update_layout(title: "Hiding a Specific Legend Entry")
|> Plotly.show()