Powered by AppSignal & Oban Pro

Custom Sized Subplot

02_custom_sized_subplot.livemd

Custom Sized Subplot

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

Section

Set xaxis.domain / xaxis2.domain as [start, end] fractions of the total plot width (0.0–1.0) to control column proportions. A small gap between domains prevents the axes from touching.

alias Plotly.{Figure, Scatter}

Figure.new()
|> Figure.add_trace(Scatter.new(x: [1, 2, 3], y: [4, 5, 6], name: "Wide"))
|> Figure.add_trace(Scatter.new(x: [1, 2, 3], y: [2, 3, 4], xaxis: "x2", yaxis: "y2", name: "Narrow"))
|> Figure.update_layout(
  title: "Custom Sized Subplots",
  xaxis: %{domain: [0, 0.65]},
  xaxis2: %{domain: [0.70, 1.0]},
  yaxis2: %{anchor: "x2"}
)
|> Plotly.show()