BarChart(x=None, y=None, orientation=Orientation.VERTICAL, layout=BarLayout.GROUPED, colors=None, value_labels=None)
Source¶
Bases: Chart
Chart drawing each value as a bar, used by Plot.bar.
Each x value gets its own position, labeled with that value, in the order of the rows. A missing value
draws no bar, and a row whose x text is missing is left out.
Changed in version 0.2.0
Adds value_labels, which writes the value of each bar.
Version history (1)
Added in version 0.1.0
Parameters:
-
x(str | None, default:None)For a Table, the column labeling the bars: numbers, dates, datetimes, times of day (labeled
HH:MM), texts or booleans, the row numbers when omitted. An Array takes none, its rows being numbered. -
y(list[str] | None, default:None)For a Table, the columns drawn, holding numbers, one series of bars each. A Table needs it, even for a single column. An Array takes none: when omitted, each of its columns is a series.
-
orientation(Orientation, default:Orientation.VERTICAL)The direction of the bars,
Orientation.VERTICALby default. -
layout(BarLayout, default:BarLayout.GROUPED) -
colors(Sequence[Color | CustomColor] | None, default:None)One color per series, the colors of the default cycle when omitted. The chart keeps its own list.
-
value_labels(ValueLabels | None, default:None)The value written on each bar and its number of decimals, such as
ndp.ValueLabels(decimals=2). When omitted, no value is written.
Raises:
-
InvalidTypeErrorWhen a setting is not of the type its annotation names.
-
InvalidColumnNameErrorWhen
xor a name inyis an empty text. -
EmptyListErrorWhen
yorcolorsis an empty list. -
DuplicateColumnErrorWhen a column name appears twice in
y.
Examples:
import numdaplot as ndp
cities = ndp.Array.from_list(["Paris", "Lyon", "Pau"])
sales_2025 = ndp.Array.from_list([120.0, 80.0, 45.0])
sales_2026 = ndp.Array.from_list([150.0, 95.0, 40.0])
sales = ndp.Table.from_arrays({"city": cities, "2025": sales_2025, "2026": sales_2026})
chart = ndp.BarChart(x="city", y=["2025", "2026"])
plot = ndp.Plot.bar(sales, chart)
plot.show()