Grouped Box Plot
Mix.install([
{:plotly_ex, "~> 0.3"},
{:kino, "~> 0.18"}
])
Section
Assign the same x: category values across multiple Box traces to group them side-by-side.
layout.boxmode: "group" positions boxes of the same category next to each other.
alias Plotly.{Figure, Box}
x = ["day 1", "day 1", "day 1", "day 2", "day 2", "day 2"]
Figure.new()
|> Figure.add_trace(Box.new(y: [0.2, 0.2, 0.6, 1.0, 0.5, 0.4], x: x, name: "kale", marker: %{color: "#3D9970"}))
|> Figure.add_trace(Box.new(y: [0.6, 0.7, 0.3, 0.6, 0.0, 0.5], x: x, name: "radishes", marker: %{color: "#FF4136"}))
|> Figure.add_trace(Box.new(y: [0.1, 0.3, 0.1, 0.9, 0.6, 0.6], x: x, name: "carrots", marker: %{color: "#FF851B"}))
|> Figure.update_layout(
title: "Grouped Box Plot",
yaxis: %{title: "normalized moisture", zeroline: false},
boxmode: "group"
)
|> Plotly.show()