barplot¶
barplot(data, *, x, y, hue=None, order=None, hue_order=None, estimator=None, orient=None, color=None, palette=None)
¶
Plot a bar chart with optional aggregation.
Accepts any DataFrame supported by narwhals (pandas, polars, PyArrow, etc.).
Orientation is inferred from column types unless overridden with orient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
IntoFrame
|
Input data. Any narwhals-compatible DataFrame or LazyFrame. |
required |
x
|
str
|
Column name for the x-axis. |
required |
y
|
str
|
Column name for the y-axis. |
required |
hue
|
str | None
|
Column name for grouping into separate series. |
None
|
order
|
list | None
|
Explicit category order for the categorical axis. |
None
|
hue_order
|
list | None
|
Explicit order for hue levels. |
None
|
estimator
|
Expr | None
|
Aggregation expression (narwhals Expr). Defaults to mean. |
None
|
orient
|
str | None
|
Force orientation — |
None
|
color
|
str | None
|
Single colour for all bars (CSS colour string). |
None
|
palette
|
list | None
|
List of colours, one per hue level. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
XYChart |
XYChart
|
An instance ready to render or further configure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a required column is missing or |