Categorical comparisons
Compare values across named categories such as products, animals, or regions.
Plotly · Class
go.Bar creates an interactive bar-chart trace for Plotly graph-object figures. Configure coordinates with x and y, then add labels, hover text, orientation, and multi-trace layout behavior as needed.
go.Bar constructs a bar trace for a plotly.graph_objects.Figure. Supply category or numeric coordinates through x and y; additional trace properties control labels, hover content, orientation, styling, and grouping.
plotly.graph_objects.Bar(arg=None, alignmentgroup=None, base=None, basesrc=None, cliponaxis=None, constraintext=None, customdata=None, customdatasrc=None, dx=None, dy=None, error_x=None, error_y=None, hoverinfo=None, hoverinfosrc=None, hoverlabel=None, hovertemplate=None, hovertemplatesrc=None, hovertext=None, hovertextsrc=None, ids=None, idssrc=None, insidetextanchor=None, insidetextfont=None, legend=None, legendgroup=None, legendgrouptitle=None, legendrank=None, marker=None, meta=None, metasrc=None, name=None, offset=None, offsetgroup=None, offsetsrc=None, opacity=None, orientation=None, outsidetextfont=None, selected=None, selectedpoints=None, showlegend=None, stream=None, text=None, textangle=None, textfont=None, textinfo=None, textposition=None, texttemplate=None, texttemplatesrc=None, uid=None, uirevision=None, unselected=None, visible=None, width=None, x=None, x0=None, xaxis=None, xcalendar=None, xsrc=None, y=None, y0=None, yaxis=None, ycalendar=None, ysrc=None, zorder=None, **kwargs)| Name | Type | Description |
|---|---|---|
x | array-like | Bar coordinates or category labels. |
y | array-like | Bar coordinates or numeric values. |
text | array-like | Text displayed or associated with each bar. |
hovertext | array-like | Custom hover content for bars. |
orientation | string | Controls the bar direction; use "h" for horizontal bars. |
A plotly.graph_objects.Bar bar-trace object.
x with numeric measurements in y.hovertext when each bar needs custom hover content.text and choose an automatic text position to display values on the bars.barmode setting to configure how multiple bar traces are arranged.go.Bar is a graph-object trace; it must be used with the Plotly graph-objects figure workflow rather than treated as a complete figure.textposition to "auto" and provide text values.import plotly.graph_objects as go
fig = go.Figure(go.Bar(
x=["A", "B", "C"],
y=[20, 14, 23],
text=[20, 14, 23],
textposition="auto",
))
fig.show()Creates a bar trace with categorical x-values and numeric y-values, then displays it.
Compare values across named categories such as products, animals, or regions.
Present several series together and control whether bars are grouped or stacked.
Show values beside marks or provide custom information on hover.
Rotate the chart layout so categories occupy the vertical axis.
go.Bar used for?go.Bar represents one bar-chart trace. It is typically passed to go.Figure, either directly or in the figure's data list, and fig.show() renders the result.
Follow-up: How would you add another series? Add another go.Bar trace with fig.add_trace() and configure the layout's barmode, such as "stack" or "group".
x, y, and orientation determine a bar chart?Use x for the categories or horizontal coordinates and y for the corresponding values in a standard vertical bar chart. The arrays should describe matching observations.
Follow-up: How would you make horizontal bars? Swap the data roles as appropriate and set orientation="h"; the official horizontal-bar example supplies values through x and categories through y.
A bar trace can expose values directly on the marks by assigning a sequence to text and setting textposition="auto". Hover-specific annotations can instead be supplied with hovertext.
Follow-up: How can multiple traces be combined? Add each trace to the same figure and set a layout bar mode, for example fig.update_layout(barmode="stack").
plotly.graph_objects.Figurefig.add_trace()fig.update_layout()barmodeplotly.express.bar