image_cmap
Gridded & matrix
Minimal call
import math
grid = [[math.sin(r * 0.15) + math.cos(col * 0.1) for col in range(80)]
for r in range(60)]
c = pt.chart(xlabel="col", ylabel="row")
c.add_image_cmap(grid, cmap="magma")
Worked example
import math
import plotlet as pt
data = [[math.sin(2 * (-3 + 6 * col / 159)) * math.cos(3 * (-2 + 4 * row / 119))
+ 0.3 * (-3 + 6 * col / 159)
for col in range(160)] for row in range(120)]
c = pt.chart(title="image_cmap", xlabel="x", ylabel="y",
data_width=360, data_height=240)
c.add_image_cmap(data, cmap="RdBu_r", center=0, extent=(-3, 3, -2, 2),
legend={"label": "amplitude"})
Docstring
2-D value matrix → colored grid via a colormap. One scalar per cell.
For real pixel data — an (H, W, 3|4) RGB(A) array where each cell already
IS a color — use `add_image_rgba` instead; every mapping kwarg here
(cmap, vmin/vmax, norm, center, the colorbar legend) assumes scalar
cells and has no meaning for pixel data.
Rendering branches between many <rect>s and one PNG. The threshold
(`image_max_rects` in spec.json) trades vector cleanliness
for SVG file size. Below the threshold, each cell is its own <rect> — sharp
at any zoom. Above, the whole image is encoded as base64 PNG. A grid
denser than `raster.oversample` cells per display pixel is mean-pooled
down to that cap before encoding (see `_png_pass`).
`origin` controls vertical orientation. Default `"lower"` puts row 0 at
the BOTTOM of the data rectangle (Cartesian). Opt in to `"upper"` for
matrix-style display (row 0 at top, what you see when you print the
array); the panel auto-inverts the y-axis in that case so tick "0"
lands next to row 0.
Color mapping goes through `ContinuousNorm`, which supports `norm="log"`
and `center=` on top of the default linear range.