Powered by AppSignal & Oban Pro

Adjusting Height, Width, and Margins

97_adjusting_height_width_and_margins.livemd

Adjusting Height, Width, and Margins

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

Section

Set layout.width and layout.height (in pixels) together with layout.autosize: false to fix the chart dimensions. Use layout.margin with keys l (left), r (right), b (bottom), t (top), and pad to control spacing around the plot area.

alias Plotly.{Figure, Scatter}

Figure.new()
|> Figure.add_trace(
  Scatter.new(
    x: [0, 1, 2, 3, 4, 5, 6, 7, 8],
    y: [0, 1, 2, 3, 4, 5, 6, 7, 8],
    mode: "markers"
  )
)
|> Figure.update_layout(
  autosize: false,
  width: 500,
  height: 500,
  margin: %{l: 50, r: 50, b: 100, t: 100, pad: 4},
  paper_bgcolor: "LightSteelBlue",
  plot_bgcolor: "LightSteelBlue"
)
|> Plotly.show()