Marks¶
A mark draws the rows of a Chart's data as lines, bars, areas, points, rules, rectangles or sectors. Marks go in the chart's marks list. Marks in one list share the data and the axes, so they draw on top of each other in list order.
nib.Chart(
data=[{"month": "Jan", "sales": 120}, {"month": "Feb", "sales": 180}],
marks=[
nib.BarMark(x="month", y="sales"),
nib.RuleMark(y=150),
],
)
Positions¶
A position argument (x, y, y_start, angle and so on) names a data column. A bare string is a column name, and nib.PlottableField("sales") is the same column written explicitly. PlottableField also takes a type that tells the chart how to scale the column; see PlottableField.
RuleMark positions also take a constant: a number, or nib.PlottableValue(...) for a constant category such as nib.PlottableValue("Mar"). See Column names and constants.
Shared parameters¶
Every mark takes these two parameters.
| Parameter | Type | Default | Description |
|---|---|---|---|
foreground_style |
str | PlottableField |
None |
The mark's colour. A colour string ("#3B82F6", "rgb(59, 130, 246)" or a listed colour name) or a gradient sets a fixed colour. A PlottableField or any other string names a column, and each distinct value of that column gets its own colour and a legend entry. The full rule is in foreground_style. |
opacity |
float |
None |
Opacity of the mark from 0.0 (transparent) to 1.0 (opaque). Defaults to 1.0. |
LineMark¶

Connects the rows with a line. Symbols can mark each data point.
nib.LineMark(x, y, foreground_style=None, symbol=None, interpolation=None, line_width=None, opacity=None)
| Parameter | Type | Default | Description |
|---|---|---|---|
x |
str | PlottableField |
required | Column for the x position. |
y |
str | PlottableField |
required | Column for the y position. |
symbol |
SymbolShape | str | PlottableField |
None |
Marker shape at each data point: a SymbolShape or its string value, or a PlottableField to pick the shape from a column. |
interpolation |
InterpolationMethod | str |
None |
How the line runs between points. See InterpolationMethod. Defaults to LINEAR. |
line_width |
float |
None |
Width of the line in points. Defaults to 2. |
Basic line chart¶

import nib
def main(app: nib.App):
app.title = "Temperature"
app.icon = nib.SFSymbol("thermometer.medium")
app.width = 360
app.height = 290
app.build(
nib.VStack(
controls=[
nib.Text("Average temperature", font=nib.Font.HEADLINE),
nib.Chart(
data=[
{"month": "Jan", "temp": 5},
{"month": "Feb", "temp": 7},
{"month": "Mar", "temp": 12},
{"month": "Apr", "temp": 17},
{"month": "May", "temp": 22},
{"month": "Jun", "temp": 26},
],
marks=[
nib.LineMark(x="month", y="temp", foreground_style="#ff9f0a")
],
width=320,
height=200,
),
],
spacing=8,
padding=20,
alignment=nib.HorizontalAlignment.LEADING,
)
)
nib.run(main)
Styled line with symbols¶

import nib
def main(app: nib.App):
app.title = "Weight"
app.icon = nib.SFSymbol("scalemass")
app.width = 380
app.height = 260
app.build(
nib.Chart(
data=[
{"week": "W1", "kg": 82.4},
{"week": "W2", "kg": 81.9},
{"week": "W3", "kg": 81.1},
{"week": "W4", "kg": 81.3},
{"week": "W5", "kg": 80.2},
{"week": "W6", "kg": 79.6},
],
marks=[
nib.LineMark(
x="week",
y="kg",
foreground_style="#0a84ff",
symbol=nib.SymbolShape.CIRCLE,
line_width=2.5,
interpolation=nib.InterpolationMethod.MONOTONE,
),
],
y_axis=nib.ChartAxis(label="kg", grid_lines=True),
width=380,
height=260,
padding=20,
)
)
nib.run(main)
BarMark¶

Draws one bar per row. The orientation follows which column is the category: a category on x and a number on y gives vertical bars, and swapping them gives horizontal bars. Bars that share an x and are split by a foreground_style column stack.
nib.BarMark(x=None, y=None, width=None, height=None, foreground_style=None, stacking=None, corner_radius=None, opacity=None)
| Parameter | Type | Default | Description |
|---|---|---|---|
x |
str | PlottableField |
None |
Column for the x axis. For vertical bars, the category column. |
y |
str | PlottableField |
None |
Column for the y axis. For vertical bars, the value column (bar height). |
width |
float |
None |
Fixed bar width in points. Bars are sized to the available space when omitted. |
height |
float |
None |
Fixed bar height in points. Bars are sized by the y values when omitted. |
stacking |
StackingMethod | str |
None |
How bars of several series combine. See StackingMethod. Defaults to STANDARD. |
corner_radius |
float |
None |
Radius of the bar corners in points. |
Simple vertical bar chart¶

import nib
def main(app: nib.App):
app.title = "Steps"
app.icon = nib.SFSymbol("figure.walk")
app.width = 360
app.height = 290
app.build(
nib.VStack(
controls=[
nib.Text("Steps this week", font=nib.Font.HEADLINE),
nib.Chart(
data=[
{"day": "Mon", "steps": 8200},
{"day": "Tue", "steps": 10400},
{"day": "Wed", "steps": 6100},
{"day": "Thu", "steps": 9800},
{"day": "Fri", "steps": 12300},
{"day": "Sat", "steps": 4300},
{"day": "Sun", "steps": 7600},
],
marks=[nib.BarMark(x="day", y="steps", foreground_style="#30d158")],
width=320,
height=200,
),
],
spacing=8,
padding=20,
alignment=nib.HorizontalAlignment.LEADING,
)
)
nib.run(main)
Horizontal bar chart¶

import nib
def main(app: nib.App):
app.title = "Languages"
app.icon = nib.SFSymbol("chart.bar.xaxis")
app.width = 380
app.height = 290
app.build(
nib.VStack(
controls=[
nib.Text("Lines of code by language", font=nib.Font.HEADLINE),
nib.Chart(
data=[
{"lang": "Python", "lines": 45_000},
{"lang": "Swift", "lines": 38_000},
{"lang": "Markdown", "lines": 12_000},
{"lang": "Shell", "lines": 2_400},
],
marks=[
nib.BarMark(x="lines", y="lang", foreground_style="#ff9f0a")
],
width=340,
height=200,
),
],
spacing=8,
padding=20,
alignment=nib.HorizontalAlignment.LEADING,
)
)
nib.run(main)
AreaMark¶

Fills the region between a baseline and the row's y value. The baseline is zero unless y_start names a lower-boundary column, which draws a range or band.
nib.AreaMark(x, y, y_start=None, foreground_style=None, interpolation=None, stacking=None, opacity=None)
| Parameter | Type | Default | Description |
|---|---|---|---|
x |
str | PlottableField |
required | Column for the x position. |
y |
str | PlottableField |
required | Column for the upper boundary of the area. |
y_start |
str | PlottableField |
None |
Column for the lower boundary of the area. The area starts at zero when omitted. |
interpolation |
InterpolationMethod | str |
None |
How the edge runs between points. See InterpolationMethod. |
stacking |
StackingMethod | str |
None |
How areas of several series combine. CENTER gives a stream graph. See StackingMethod. Defaults to STANDARD. |
An opacity between 0.3 and 0.7 keeps overlapping areas readable.
Basic area chart¶

import nib
def main(app: nib.App):
app.title = "Traffic"
app.icon = nib.SFSymbol("chart.line.uptrend.xyaxis")
app.width = 360
app.height = 290
app.build(
nib.VStack(
controls=[
nib.Text("Visitors", font=nib.Font.HEADLINE),
nib.Chart(
data=[
{"day": "Mon", "visits": 320},
{"day": "Tue", "visits": 410},
{"day": "Wed", "visits": 380},
{"day": "Thu", "visits": 520},
{"day": "Fri", "visits": 610},
{"day": "Sat", "visits": 290},
{"day": "Sun", "visits": 240},
],
marks=[
nib.AreaMark(
x="day",
y="visits",
foreground_style="#0a84ff",
opacity=0.35,
),
nib.LineMark(x="day", y="visits", foreground_style="#0a84ff"),
],
width=320,
height=200,
),
],
spacing=8,
padding=20,
alignment=nib.HorizontalAlignment.LEADING,
)
)
nib.run(main)
Stacked area chart¶

import nib
def main(app: nib.App):
app.title = "Energy"
app.icon = nib.SFSymbol("bolt.fill")
app.width = 380
app.height = 310
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
solar = [30, 42, 65, 90, 120, 140]
wind = [80, 70, 60, 55, 40, 35]
data = [{"month": m, "kwh": v, "source": "Solar"} for m, v in zip(months, solar)]
data += [{"month": m, "kwh": v, "source": "Wind"} for m, v in zip(months, wind)]
app.build(
nib.VStack(
controls=[
nib.Text("Generation by source", font=nib.Font.HEADLINE),
nib.Chart(
data=data,
marks=[
nib.AreaMark(
x="month",
y="kwh",
foreground_style=nib.PlottableField("source"),
stacking=nib.StackingMethod.STANDARD,
),
],
legend=nib.ChartLegend(position="bottom"),
width=340,
height=220,
),
],
spacing=8,
padding=20,
alignment=nib.HorizontalAlignment.LEADING,
)
)
nib.run(main)
PointMark¶

Draws one symbol per row. Two numeric columns give a scatter plot, and a PointMark over a LineMark marks the line's data points. Points share a shape, size and colour, or take the shape and colour from a column.
nib.PointMark(x, y, foreground_style=None, symbol=None, symbol_size=None, opacity=None)
| Parameter | Type | Default | Description |
|---|---|---|---|
x |
str | PlottableField |
required | Column for the x position. |
y |
str | PlottableField |
required | Column for the y position. |
symbol |
SymbolShape | str | PlottableField |
None |
Marker shape: a SymbolShape or its string value, or a PlottableField to pick the shape from a column. |
symbol_size |
float |
None |
Size of each symbol in square points. Defaults to 100. |
A lower opacity keeps overlapping points in a dense scatter plot visible.
Basic scatter plot¶

import nib
def main(app: nib.App):
app.title = "Scatter"
app.icon = nib.SFSymbol("chart.dots.scatter")
app.width = 380
app.height = 280
app.build(
nib.Chart(
data=[
{"height": 160, "weight": 55},
{"height": 165, "weight": 60},
{"height": 168, "weight": 66},
{"height": 170, "weight": 72},
{"height": 175, "weight": 80},
{"height": 180, "weight": 85},
{"height": 183, "weight": 79},
{"height": 188, "weight": 92},
],
marks=[nib.PointMark(x="height", y="weight", foreground_style="#bf5af2")],
x_axis=nib.ChartAxis(label="Height (cm)"),
y_axis=nib.ChartAxis(label="Weight (kg)", grid_lines=True),
width=380,
height=280,
padding=20,
)
)
nib.run(main)
Colored by category¶

import nib
def main(app: nib.App):
app.title = "Iris"
app.icon = nib.SFSymbol("leaf")
app.width = 400
app.height = 320
data = [
{"sepal": 5.1, "petal": 1.4, "species": "Setosa"},
{"sepal": 4.9, "petal": 1.5, "species": "Setosa"},
{"sepal": 5.4, "petal": 1.7, "species": "Setosa"},
{"sepal": 7.0, "petal": 4.7, "species": "Versicolor"},
{"sepal": 6.4, "petal": 4.5, "species": "Versicolor"},
{"sepal": 5.9, "petal": 4.2, "species": "Versicolor"},
{"sepal": 6.3, "petal": 6.0, "species": "Virginica"},
{"sepal": 7.1, "petal": 5.9, "species": "Virginica"},
{"sepal": 6.5, "petal": 5.8, "species": "Virginica"},
]
app.build(
nib.Chart(
data=data,
marks=[
nib.PointMark(
x="sepal", y="petal", foreground_style=nib.PlottableField("species")
)
],
x_axis=nib.ChartAxis(label="Sepal length (cm)"),
y_axis=nib.ChartAxis(label="Petal length (cm)"),
legend=nib.ChartLegend(position="bottom"),
width=400,
height=300,
padding=20,
)
)
nib.run(main)
RuleMark¶

Draws a straight reference line for a threshold, an average, a target or an event. Pass y for a horizontal rule or x for a vertical rule. The start and end bounds turn the rule into a segment.
A number is a constant, and nib.PlottableValue(...) is a constant that can be a category and can carry a label. A string is a column name, which draws one rule per row. RuleMark(x="Mar") looks for a column named Mar; a rule at the x category "Mar" is RuleMark(x=nib.PlottableValue("Mar")).
nib.RuleMark(x=None, x_start=None, x_end=None, y=None, y_start=None, y_end=None, foreground_style=None, line_width=None, opacity=None)
All position parameters take str | float | PlottableField | PlottableValue.
| Parameter | Type | Default | Description |
|---|---|---|---|
x |
see above | None |
X position of a vertical rule. |
x_start |
see above | None |
Start of a bounded horizontal rule. |
x_end |
see above | None |
End of a bounded horizontal rule. |
y |
see above | None |
Y position of a horizontal rule. |
y_start |
see above | None |
Start of a bounded vertical rule. |
y_end |
see above | None |
End of a bounded vertical rule. |
line_width |
float |
None |
Width of the rule in points. Defaults to 1. |
Horizontal reference line (target)¶

import nib
def main(app: nib.App):
app.title = "Target"
app.icon = nib.SFSymbol("target")
app.width = 380
app.height = 290
app.build(
nib.VStack(
controls=[
nib.Text("Sales against the 100k target", font=nib.Font.HEADLINE),
nib.Chart(
data=[
{"month": "Jan", "sales": 80},
{"month": "Feb", "sales": 120},
{"month": "Mar", "sales": 95},
{"month": "Apr", "sales": 130},
{"month": "May", "sales": 88},
{"month": "Jun", "sales": 142},
],
marks=[
nib.BarMark(x="month", y="sales", foreground_style="#0a84ff"),
nib.RuleMark(y=100, foreground_style="#ff453a", line_width=2),
],
width=340,
height=200,
),
],
spacing=8,
padding=20,
alignment=nib.HorizontalAlignment.LEADING,
)
)
nib.run(main)
Vertical reference line (event marker)¶

import nib
def main(app: nib.App):
app.title = "Launch"
app.icon = nib.SFSymbol("flag")
app.width = 380
app.height = 290
days = ["1", "5", "10", "15", "20", "25", "30"]
users = [120, 135, 150, 160, 420, 510, 580]
app.build(
nib.VStack(
controls=[
nib.Text("Daily users, launch on day 15", font=nib.Font.HEADLINE),
nib.Chart(
data=[{"day": d, "users": u} for d, u in zip(days, users)],
marks=[
nib.LineMark(x="day", y="users", foreground_style="#30d158"),
nib.RuleMark(x=nib.PlottableValue("15"), foreground_style="#bf5af2", line_width=2),
],
width=340,
height=200,
),
],
spacing=8,
padding=20,
alignment=nib.HorizontalAlignment.LEADING,
)
)
nib.run(main)
RectMark¶

Draws filled rectangles in data space, for heatmaps, Gantt charts and range charts. Each axis is set either by a centre column (x or y, sized automatically per category) or by explicit bounds (x_start and x_end, or y_start and y_end):
| Arguments | Shape | Typical use |
|---|---|---|
x_start, x_end, y_start, y_end |
A rectangle with explicit bounds | Ranges on both axes |
x_start, x_end, y |
A horizontal band per category | Gantt chart |
x, y_start, y_end |
A vertical band per category | Ranges per category |
x, y |
One cell per pair of categories | Heatmap |
nib.RectMark(x=None, x_start=None, x_end=None, y=None, y_start=None, y_end=None, foreground_style=None, corner_radius=None, opacity=None)
| Parameter | Type | Default | Description |
|---|---|---|---|
x |
str | PlottableField |
None |
Column for the x centre. The cell width is automatic. |
x_start |
str | PlottableField |
None |
Column for the left edge. |
x_end |
str | PlottableField |
None |
Column for the right edge. |
y |
str | PlottableField |
None |
Column for the y centre. The cell height is automatic. |
y_start |
str | PlottableField |
None |
Column for the bottom edge. |
y_end |
str | PlottableField |
None |
Column for the top edge. |
corner_radius |
float |
None |
Radius of the corners in points. |
In a heatmap, foreground_style=nib.PlottableField("value") colours each cell by its value.
Heatmap¶

import nib
def main(app: nib.App):
app.title = "Activity"
app.icon = nib.SFSymbol("square.grid.3x3.fill")
app.width = 380
app.height = 300
levels = {
"Mon": ["low", "high", "medium", "low"],
"Tue": ["medium", "high", "high", "low"],
"Wed": ["low", "medium", "high", "medium"],
"Thu": ["high", "high", "medium", "low"],
"Fri": ["medium", "low", "low", "low"],
}
hours = ["9am", "11am", "2pm", "4pm"]
data = [
{"weekday": day, "hour": hour, "intensity": level}
for day, row in levels.items()
for hour, level in zip(hours, row)
]
app.build(
nib.Chart(
data=data,
marks=[
nib.RectMark(
x="weekday",
y="hour",
foreground_style=nib.PlottableField("intensity"),
)
],
legend=nib.ChartLegend(position="bottom"),
width=380,
height=280,
padding=20,
)
)
nib.run(main)
Gantt chart (range chart)¶

import nib
def main(app: nib.App):
app.title = "Plan"
app.icon = nib.SFSymbol("calendar.badge.clock")
app.width = 420
app.height = 280
tasks = [
{"task": "Design", "start": 0, "end": 3, "status": "complete"},
{"task": "Develop", "start": 2, "end": 7, "status": "in progress"},
{"task": "Test", "start": 6, "end": 9, "status": "pending"},
{"task": "Release", "start": 9, "end": 10, "status": "pending"},
]
app.build(
nib.Chart(
data=tasks,
marks=[
nib.RectMark(
x_start="start",
x_end="end",
y="task",
foreground_style=nib.PlottableField("status"),
corner_radius=4,
),
],
x_axis=nib.ChartAxis(label="Week"),
legend=nib.ChartLegend(position="bottom"),
width=420,
height=260,
padding=20,
)
)
nib.run(main)
SectorMark¶

Draws the segments of a pie or donut chart. Each sector's size is proportional to its angle value, and foreground_style=nib.PlottableField("category") gives each sector its own colour. An inner_radius above zero makes a donut.
nib.SectorMark(angle, foreground_style=None, inner_radius=None, outer_radius=None, corner_radius=None, opacity=None)
| Parameter | Type | Default | Description |
|---|---|---|---|
angle |
str | PlottableField |
required | Column whose values set the sector sizes. A sector with value 20 is twice the size of one with value 10. |
inner_radius |
float |
None |
Inner radius in points. 0 (the default) draws a pie, a positive value a donut. |
outer_radius |
float |
None |
Outer radius in points. Sized to the available space when omitted. |
corner_radius |
float |
None |
Radius of the sector corners in points. |
Pie chart¶

import nib
def main(app: nib.App):
app.title = "Budget"
app.icon = nib.SFSymbol("chart.pie")
app.width = 340
app.height = 360
app.build(
nib.VStack(
controls=[
nib.Text("Spending by category", font=nib.Font.HEADLINE),
nib.Chart(
data=[
{"category": "Rent", "value": 1200},
{"category": "Food", "value": 480},
{"category": "Transport", "value": 160},
{"category": "Fun", "value": 220},
],
marks=[
nib.SectorMark(
angle="value",
foreground_style=nib.PlottableField("category"),
)
],
legend=nib.ChartLegend(position="bottom"),
width=300,
height=280,
),
],
spacing=8,
padding=20,
)
)
nib.run(main)
Donut chart¶

import nib
def main(app: nib.App):
app.title = "Disk"
app.icon = nib.SFSymbol("internaldrive")
app.width = 320
app.height = 340
app.build(
nib.ZStack(
controls=[
nib.Chart(
data=[
{"segment": "Apps", "gb": 48},
{"segment": "Photos", "gb": 112},
{"segment": "System", "gb": 15},
{"segment": "Free", "gb": 325},
],
marks=[
nib.SectorMark(
angle="gb",
foreground_style=nib.PlottableField("segment"),
inner_radius=70,
outer_radius=110,
),
],
legend=nib.ChartLegend(position="bottom"),
width=280,
height=300,
),
nib.VStack(
controls=[
nib.Text("500 GB", font=nib.Font.TITLE2),
nib.Text(
"total",
font=nib.Font.CAPTION,
foreground_color=nib.Color.SECONDARY,
),
],
spacing=0,
padding={"bottom": 36},
),
],
padding=16,
)
)
nib.run(main)