Skip to content

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) -> Mark

Parameters ​

An embedded raster/SVG image. Box geometry via the shared dims channels.

OptionTypeDefaultDescription
keystrInternal per-node key override.
hrefstrRequired. Image URL or data URI.
filterstrRaw SVG filter attribute.
opacityfloatOpacity, 0 to 1.
preserve_aspect_ratiostr"xMidYMid meet"Raw SVG preserveAspectRatio value.
debugboolDev-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 ​

OptionTypeDefaultDescription
xint | float | strLeft edge position.
cxint | float | strCenter x.
x2int | float | strRight edge position.
wint | float | strWidth.
em_xboolEmbed x in the parent's x space.
yint | float | strStart edge on y: the top edge where y reads top-down, the bottom edge where it grows upward.
cyint | float | strCenter y.
y2int | float | strOther y edge position.
hint | float | strHeight.
em_yboolEmbed y in the parent's y space.
dimsdictBox 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:

  • w and h — the image is drawn at exactly that size.
  • w only (or h only) — 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))