rect
Draws a rectangle for each data item. The most common mark — bars, stacked bars, mosaic tiles, and waffle cells are all rectangles.
from gofish import chart, spread, rect
chart(seafood).flow(spread(by="lake", dir="x")).mark(rect(h="count")).render(
w=500, h=300, axes=True
)Signature
rect(*, x=None, cx=None, x2=None, w=None, em_x=None,
y=None, cy=None, y2=None, h=None, em_y=None,
dims=None,
fill=None, stroke=None, stroke_width=None, opacity=None, filter=None,
rx=None, ry=None, aspect_ratio=None, key=None) -> MarkClosed signature — no catch-all **kwargs. An unrecognized keyword raises a TypeError at the call site instead of being accepted and then quietly ignored at render time, which is the class of bug that motivated closing it (see Frontend IR).
Parameters
A rectangle. Box geometry via the shared dims channels.
| Option | Type | Default | Description |
|---|---|---|---|
key | str | Internal per-node key override. | |
rx | float | 0 | Corner radius, x. |
ry | float | 0 | Corner radius, y. |
aspect_ratio | float | w/h ratio to enforce; the constraining axis wins when both are data-driven. | |
debug | bool | Dev-only flag: logs this mark's key and datum to the console as it is built. It changes nothing about what is drawn. |
Box dimensions
| Option | Type | Default | Description |
|---|---|---|---|
x | int | float | str | Left edge position. | |
cx | int | float | str | Center x. | |
x2 | int | float | str | Right edge position. | |
w | int | float | str | Width. | |
em_x | bool | Embed x in the parent's x space. | |
y | int | float | str | Start edge on y: the top edge where y reads top-down, the bottom edge where it grows upward. | |
cy | int | float | str | Center y. | |
y2 | int | float | str | Other y edge position. | |
h | int | float | str | Height. | |
em_y | bool | Embed y in the parent's y space. | |
dims | dict | Box dimensions by axis name: x/y, or a name the enclosing coordinate space declares (polar theta/r, geo lon/lat). Each value is a position (like x) or an interval {min, center, max, size, embedded}. |
Paint
| Option | Type | Default | Description |
|---|---|---|---|
fill | str | Fill color, or a field name for a color scale. | |
stroke | str | Stroke color. Defaults to fill. | |
stroke_width | float | 0 | Stroke width in pixels. |
opacity | float | 1 | Opacity, 0 to 1. |
filter | str | Raw SVG filter attribute. |
Returns a Mark for use in .mark(). To attach a text label, chain .label(accessor, ...) on the returned mark rather than passing a label option here.
Axis names
x, y, w, and h mean the first and second axis in any coordinate space. Under polar that is the angle and the radius.
To use the names a coordinate space gives its axes, pass them in the dims dict. Each key is an axis name, and each value is either a position (like x) or a dict with any of "min", "center", "max", "size", and "embedded":
# Inside polar(): the same wedge as rect(w=0.4, h="value")
rect(dims={"theta": {"size": 0.4}, "r": {"size": "value"}})"x" and "y" are always valid keys too. A name the enclosing coordinate space does not declare raises an error that lists the ones it does, and setting the same part of an axis twice (for example w and dims["theta"]["size"]) is an error. dims is the one keyword for axis names, so the rest of the signature stays closed. The same keyword works on ellipse, petal, text, image, and layer.
Encoding
Each option takes a constant or a field name (a string column in your data):
rect(h="count", fill="species") # height and color from fields
rect(h="count", fill="#4e79a7") # height from data, constant color
rect(w=20, h="count") # constant width, data-driven heightExamples
# Stacked bars
chart(seafood).flow(
spread(by="lake", dir="x"),
stack(by="species", dir="y"),
).mark(rect(h="count", fill="species"))
# Rounded, outlined tiles
chart(data).mark(rect(h="count", rx=4, stroke="white", stroke_width=2))