Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Plotly · Class

go.Box

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.

How it works

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.

Syntax

go.Box(arg=None, alignmentgroup=None, ...)

Parameters

NameTypeDescription
xarray-likeValues used to calculate the box-plot statistics when supplied as observations.
yarray-likeValues used to calculate the box-plot statistics when supplied as observations.
namestrTrace label used to distinguish this distribution in the figure.

Returns

A plotly.graph_objects.Box trace object.

Key points

  • Use go.Box when constructing a box-plot trace directly with Plotly's graph-objects API.
  • A box plot can be created by passing numeric observations to the y argument and adding the trace to a figure.
  • Multiple Box traces can be added to one figure to compare separate distributions.
  • Observations may be supplied through x instead of y when the box plot is oriented along the other axis.
  • Plotly Express provides a separate px.box function, while go.Box is the lower-level graph-objects option.

Common mistakes

  • The class has many configurable trace attributes; consult the dedicated box reference for options rather than assuming defaults.

Example: Basic box plot

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.

When to use it

Place multiple distributions in one figure

Compare distributions

Visualize the distribution of numeric observations

Inspect spread and outliers

Use direct trace construction when Plotly Express is not enough

Build custom graph-object figures

Interview questions

QWhat is go.Box used for?

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.

QShow the basic construction pattern.

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.

QWhen would you choose go.Box instead of Plotly Express?

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.Figure
  • Figure.add_trace
  • px.box
  • box trace reference

Source: Box plots in Python. Checked 2026-10-15.