yr.bar_chart
bar_chart(
data: object,
x: str | None = None,
y: str | Sequence[str] | None = None,
colour: str | Sequence[str] | None = None,
horizontal: bool = False,
stack: bool = True,
) → NoneRender a bar chart.
Parameters
data
type: object
Chart data; typically a pandas DataFrame.
x
type: str | None = None
Column name to use for the x-axis.
y
type: str | Sequence[str] | None = None
Column name (or names) to plot on the y-axis.
colour
type: str | Sequence[str] | None = None
Column name (or names) used to colour the bars.
horizontal
type: bool = False
Orient bars horizontally rather than vertically.
stack
type: bool = True
Stack multiple series rather than grouping side-by-side.
Examples
import pandas as pd
df = pd.DataFrame({"quarter": ["Q1", "Q2", "Q3", "Q4"], "revenue": [120, 145, 98, 167]})
bar_chart(df, x="quarter", y="revenue")
Grouped by colour:
df = pd.DataFrame({
"quarter": ["Q1", "Q2", "Q1", "Q2"],
"revenue": [120, 145, 98, 167],
"region": ["North", "North", "South", "South"],
})
bar_chart(df, x="quarter", y="revenue", colour="region", stack=False)