ChartAxis & ChartLegend¶

Configuration objects for chart axes and legends. These are passed to the Chart constructor via the x_axis, y_axis, and legend parameters. They do not render anything on their own.
This page also documents the supporting types used for chart data encoding: PlottableField, PlottableValue, InterpolationMethod, StackingMethod, SymbolShape, AxisPosition, LegendPosition, and PlottableType.
ChartAxis¶
Controls the appearance and behavior of a chart axis, including position, labels, grid lines, value formatting, and colors.
Constructor¶
nib.ChartAxis(
position=None,
label=None,
grid_lines=None,
hidden=None,
format=None,
values=None,
label_color=None,
grid_color=None,
)
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
position |
str | AxisPosition |
None |
Position of the axis. For x-axis: "bottom" (default) or "top". For y-axis: "leading" (default, left in LTR) or "trailing". |
label |
str |
None |
Text label displayed alongside the axis (e.g., "Temperature (F)"). |
grid_lines |
bool |
None |
Whether to display grid lines extending from tick marks across the plot area. |
hidden |
bool |
None |
Whether to completely hide the axis, including tick marks and labels. |
format |
str |
None |
Format for numeric tick values: "number", "currency" (the user's locale currency), or "percent" (0.5 is 50%). Defaults to automatic formatting. |
values |
list |
None |
Explicit list of values to show as tick marks. Only these values appear on the axis. |
label_color |
str |
None |
Color for axis labels and tick text. Accepts hex strings or named colors. |
grid_color |
str |
None |
Color for grid lines (when grid_lines=True). Accepts hex strings or named colors. |
Examples¶
# Basic axis with label
nib.ChartAxis(label="Revenue ($)")
# Axis with grid lines and formatting
nib.ChartAxis(
label="Sales",
grid_lines=True,
format="currency",
label_color="#666666",
grid_color="#333333",
)
# Custom tick values
nib.ChartAxis(label="Rating", values=[1, 2, 3, 4, 5])
# Hidden axis
nib.ChartAxis(hidden=True)
# Axis positioned at top
nib.ChartAxis(position=nib.AxisPosition.TOP, label="Date")
ChartLegend¶
Controls the position and visibility of the chart legend. The legend is automatically generated from foreground_style mappings in marks.
Constructor¶
nib.ChartLegend(
position=None,
hidden=None,
)
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
position |
str |
None |
Legend position: "top", "bottom", "leading", "trailing", or "automatic". |
hidden |
bool |
None |
Whether to hide the legend entirely. |
Examples¶
# Bottom-positioned legend
nib.ChartLegend(position="bottom")
# Hide the legend
nib.ChartLegend(hidden=True)
# Or use the shorthand on Chart
nib.Chart(data=data, marks=[...], legend=False)
PlottableField¶
A reference to a data column. A plain string means the same thing in a position argument. foreground_style and symbol need PlottableField for a column whose name would otherwise read as a colour or shape.
Constructor¶
nib.PlottableField(field, type=None)
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
field |
str |
required | Name of the data column. Must match a key in the chart's data dictionaries. |
type |
PlottableType | str |
None |
How the column is scaled: "quantitative" (numeric scale), "nominal" (discrete categories) or "temporal" (time scale). See PlottableType. |
Examples¶
# Simple field reference (same as using the string "sales" directly)
nib.PlottableField("sales")
# Explicit type: a time scale on x
nib.LineMark(
x=nib.PlottableField("timestamp", type=nib.PlottableType.TEMPORAL),
y="temperature",
)
# Color encoding by category
nib.LineMark(
x="date",
y="value",
foreground_style=nib.PlottableField("category"),
)
PlottableValue¶
A static value for chart encoding, primarily used with RuleMark to create reference lines at fixed positions with optional labels.
Constructor¶
nib.PlottableValue(value, label=None)
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
value |
int | float | str |
required | The static value. A number for quantitative axes, or a string for categorical axes. |
label |
str |
None |
Text shown with the value, such as "Target" on a reference line. |
Examples¶
# Vertical rule at the x category "Mar"
nib.RuleMark(x=nib.PlottableValue("Mar"))
# Labelled horizontal rule at y=100
nib.RuleMark(y=nib.PlottableValue(100, label="Target"))
# Without a label, a number needs no PlottableValue
nib.RuleMark(y=100)
Enumerations¶
InterpolationMethod¶
Curve interpolation methods for LineMark and AreaMark.
| Value | Description |
|---|---|
LINEAR |
Straight lines between points. Default. |
MONOTONE |
Smooth curve preserving monotonicity. No artificial peaks between points. |
CATMULL_ROM |
Smooth cubic spline through all points. May overshoot. |
CARDINAL |
Smooth curve with adjustable tension. |
STEP_START |
Horizontal step, transitioning at interval start. |
STEP_CENTER |
Horizontal step, transitioning at interval midpoint. |
STEP_END |
Horizontal step, transitioning at interval end. |
nib.LineMark(x="date", y="temp", interpolation=nib.InterpolationMethod.MONOTONE)
StackingMethod¶
Stacking modes for BarMark and AreaMark.
| Value | Description |
|---|---|
STANDARD |
Values stacked on top of each other. Y-axis reflects cumulative total. |
NORMALIZED |
Values scaled to 100% at each x position. Shows relative proportions. |
CENTER |
Values centered around the middle axis (stream graph effect). |
UNSTACKED |
Every series starts from zero and the marks overlap. |
nib.BarMark(x="q", y="rev", foreground_style=nib.PlottableField("region"),
stacking=nib.StackingMethod.STANDARD)
SymbolShape¶
Point marker shapes for PointMark and LineMark.
| Value | Description |
|---|---|
CIRCLE |
Filled circle. Default and most common. |
SQUARE |
Filled square. |
TRIANGLE |
Filled upward-pointing triangle. |
DIAMOND |
Filled diamond (rotated square). |
CROSS |
X-shaped cross. Lighter visual weight. |
PLUS |
Plus sign. Axis-aligned. |
PENTAGON |
Filled five-sided polygon. |
nib.PointMark(x="x", y="y", symbol=nib.SymbolShape.DIAMOND, symbol_size=100)
AxisPosition¶
Axis placement relative to the plot area.
| Value | Description |
|---|---|
BOTTOM |
Below the plot area. Default for x-axis. |
TOP |
Above the plot area. |
LEADING |
Left side (LTR). Default for y-axis. |
TRAILING |
Right side (LTR). |
LegendPosition¶
Legend placement relative to the chart.
| Value | Description |
|---|---|
TOP |
Above the chart. |
BOTTOM |
Below the chart. |
LEADING |
Left side (LTR). |
TRAILING |
Right side (LTR). |
AUTOMATIC |
System chooses based on available space. |
HIDDEN |
Legend is not displayed. |
PlottableType¶
Values for PlottableField(type=...). Without a type, the scale is inferred from the data.
| Value | Description |
|---|---|
QUANTITATIVE |
Numeric data on a continuous linear scale. |
NOMINAL |
Categorical data with no inherent order, on a discrete scale. |
TEMPORAL |
Date and time data, on a time scale with date-aware ticks. |