Category distribution comparison
Compare a numeric measurement across categories such as days, groups, or conditions.
Plotly · Function
Creates interactive box-and-whisker plots from tabular or array-like data. It supports grouping, facets, colors, point overlays, notches, logarithmic axes, and other figure styling options.
px.box groups rows from a data frame into box-and-whisker marks that show distribution. The box spans Q1–Q3, Q2 appears as an internal line, and default whiskers extend 1.5 IQR beyond the quartiles; grouping, faceting, orientation, point display, and styling are configurable.
plotly.express.box(data_frame=None, x=None, y=None, color=None, facet_row=None, facet_col=None, facet_col_wrap=0, facet_row_spacing=None, facet_col_spacing=None, hover_name=None, hover_data=None, custom_data=None, animation_frame=None, animation_group=None, category_orders=None, labels=None, color_discrete_sequence=None, color_discrete_map=None, orientation=None, boxmode=None, log_x=False, log_y=False, range_x=None, range_y=None, points=None, notched=False, title=None, subtitle=None, template=None, width=None, height=None) → plotly.graph_objects._figure.Figure| Name | Type | Description |
|---|---|---|
data_frame | DataFrame | array-like | dict | Data frame, array-like object, or dictionary supplying data and column names. |
x | str | int | Series | array-like | Column name, index, Series, or array-like values for the horizontal dimension or grouping. |
y | str | int | Series | array-like | Column name, index, Series, array-like values, or a list of columns for the vertical distribution. |
color | str | int | Series | array-like | Column or values used to assign colors to groups. |
facet_row | str | int | Series | array-like | Column or values used to create row facets. |
facet_col | str | int | Series | array-like | Column or values used to create column facets. |
facet_col_wrap | int | Number of facet columns before wrapping. |
facet_row_spacing | float | Spacing between facet rows. |
facet_col_spacing | float | Spacing between facet columns. |
hover_name | str | int | Series | array-like | Column or values used as the hover label. |
hover_data | list | dict | Additional data shown in hover labels. |
custom_data | list | dict | Additional custom data attached to traces. |
plotly.graph_objects._figure.Figure
import plotly.express as px
fig = px.box(
px.data.tips(),
x="day",
y="total_bill",
color="smoker",
points="all",
notched=True,
)
fig.show()Creates grouped, colored box plots of restaurant bills, displaying every underlying observation and notches.
Compare a numeric measurement across categories such as days, groups, or conditions.
Inspect the spread and possible outliers of a variable.
Compare several numeric columns in wide-form or mixed-form data.
Show subgroup differences with color, facets, or animation.
px.box returns a Plotly Figure. It groups data-frame rows into box-and-whisker marks; each box covers Q1 through Q3 and the median is shown inside it.
Follow-up: How are the default whiskers determined? They extend from the box edges by 1.5 times the IQR, where IQR is Q3 minus Q1.
Pass a column name through x to create a box for each value of that column, while y supplies the distribution being plotted. For example, x="time" and y="total_bill" creates groups by time.
Follow-up: How can multiple numeric columns be plotted? Use wide-form input by supplying a list of column names for y.
The points argument controls raw observations: "all" displays every point, "outliers" displays only outliers, and False hides them. The default is outliers.
Follow-up: What does notched=True change? It requests notched boxes, which provide a visual indication related to uncertainty around the median.
plotly.express.violinplotly.express.stripplotly.express.histogramplotly.graph_objects.Figure