Powered by AppSignal & Oban Pro

Cumulative Histogram

23_cumulative_histogram.livemd

Cumulative Histogram

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

Section

cumulative: %{enabled: true} turns a histogram into a cumulative distribution. Each bar shows how many data points fall at or below that bin's upper bound.

alias Plotly.{Figure, Histogram}

:rand.seed(:exsss, {1, 2, 3})

x = for _ <- 1..500 do
  (for _ <- 1..12, do: :rand.uniform()) |> Enum.sum() |> Kernel.-(6.0)
end

Figure.new()
|> Figure.add_trace(Histogram.new(x: x, name: "Regular",    opacity: 0.5))
|> Figure.add_trace(Histogram.new(x: x, name: "Cumulative", opacity: 0.3, cumulative: %{enabled: true}))
|> Figure.update_layout(
  title: "Cumulative Histogram",
  barmode: "overlay"
)
|> Plotly.show()