image
Draws a raster or SVG image for each data item. Use it for logos, icons, photo glyphs, or any artwork you want to place and size like a native mark.
python
from gofish import chart, image
chart([{"label": "badge"}]).mark(
image(href="https://example.com/badge.svg", w=96, h=64)
).render(w=150, h=120)Signature
python
image(href=None, w=None, h=None, x=None, y=None, debug=None) -> MarkParameters
An embedded raster/SVG image. Box geometry via the shared dims channels.
| Option | Type | Default | Description |
|---|---|---|---|
key | str | Internal per-node key override. | |
href | str | Required. Image URL or data URI. | |
filter | str | Raw SVG filter attribute. | |
opacity | float | Opacity, 0 to 1. | |
preserve_aspect_ratio | str | "xMidYMid meet" | Raw SVG preserveAspectRatio value. |
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}. |
Returns a Mark for use in .mark().
Sizing
href is required. Width and height are resolved from the image's intrinsic dimensions when not given:
wandh— the image is drawn at exactly that size.wonly (orhonly) — the missing dimension is derived from the image's intrinsic aspect ratio, so the image scales proportionally.- neither — the image renders at its intrinsic pixel dimensions. GoFish reads these by probing the loaded image (or parsing an SVG
data:URI).
Examples
python
# Fixed size
chart(data).mark(image(href=bottle_png, w=193, h=600))
# Scale to a width, keep the aspect ratio
chart(data).mark(image(href=bottle_jpg, w=90))
# Intrinsic size from a data URI
chart(data).mark(image(href=inline_badge_svg))