Place multiple distributions in one figure
Compare distributions
Plotly · Class
go.Box is Plotly's graph-objects class for building interactive box-plot traces. Add one or more Box traces to a Figure, typically by supplying observations through x or y.
go.Box creates a box-plot trace for plotly.graph_objects.Figure. Supply observations through x or y, optionally group them with categorical values, and customize the trace through its box-plot attributes before rendering the figure.
go.Box(arg=None, alignmentgroup=None, ...)| Name | Type | Description |
|---|---|---|
x | array-like | Values used to calculate the box-plot statistics when supplied as observations. |
y | array-like | Values used to calculate the box-plot statistics when supplied as observations. |
name | str | Trace label used to distinguish this distribution in the figure. |
A plotly.graph_objects.Box trace object.
import plotly.graph_objects as go
fig = go.Figure(go.Box(y=[1, 2, 3, 4, 5], name="Values"))
fig.show()Creates one interactive box plot from numeric y-values and displays it.
Compare distributions
Inspect spread and outliers
Build custom graph-object figures
go.Box is a trace class used with plotly.graph_objects.Figure to create an interactive box plot. A figure can contain multiple Box traces, each added with add_trace.
Follow-up: How would you display raw observations? Pass the observations through y or x; use boxpoints when the individual points should also be shown.
The normal construction pattern is go.Box(y=data), followed by adding the trace to a Figure and calling show. The official example also demonstrates creating a Figure and adding multiple Box traces.
Follow-up: How would you compare two distributions? Create two Box traces, give each its own data and optionally a name, then add both to the same figure.
Plotly documents go.Box as the more generic graph-objects alternative when Plotly Express is not a suitable starting point. Its available options are exposed through the box trace reference.
Follow-up: Where should attribute-level behavior be checked? Use the official box trace reference linked from the box-plots documentation.
plotly.graph_objects.FigureFigure.add_tracepx.boxbox trace reference