Powered by AppSignal & Oban Pro

Subplots with Shared Axes

04_subplots_with_shared_axes.livemd

Subplots with Shared Axes

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

Section

pattern: "coupled" in layout.grid shares axes between cells in the same row/column. Alternatively, set xaxis2.matches: "x" explicitly to link specific axis pairs.

alias Plotly.{Figure, Scatter}

Figure.new()
|> Figure.add_trace(Scatter.new(x: [1, 2, 3], y: [4, 5, 6], name: "Top"))
|> Figure.add_trace(Scatter.new(x: [1, 2, 3], y: [2, 3, 4], xaxis: "x2", yaxis: "y2", name: "Bottom"))
|> Figure.update_layout(
  title: "Shared Axes",
  grid: %{rows: 2, columns: 1, pattern: "independent"},
  xaxis2: %{matches: "x"}
)
|> Plotly.show()