Powered by AppSignal & Oban Pro

Customizing Spacing Between X and Y Ticks

06_customizing_spacing_between_x_and_y_ticks.livemd

Customizing Spacing Between X and Y Ticks

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

Section

Instead of providing explicit x: and y: lists, use x0:/y0: (starting value) with dx:/dy: (step size) to define uniformly-spaced implicit coordinates. This is more concise when spacing is constant.

alias Plotly.{Figure, Contour}

z = for i <- 0..19 do
  for j <- 0..19 do
    :math.sin(i * :math.pi() / 10) * :math.cos(j * :math.pi() / 10)
  end
end

Figure.new()
|> Figure.add_trace(
  Contour.new(
    z: z,
    x0: -2.0,
    dx: 0.2,
    y0: -2.0,
    dy: 0.2,
    colorscale: "Viridis"
  )
)
|> Figure.update_layout(title: "Contour with dx/dy Implicit Spacing")
|> Plotly.show()