Skip to content

geom_imshow

geom_imshow(
    image_data: ndarray,
    cmap: str | list[str] | None = None,
    *,
    norm: bool | None = None,
    alpha: float | None = None,
    vmin: float | None = None,
    vmax: float | None = None,
    extent: list[float]
    | tuple[float, float, float, float]
    | None = None,
    compression: int | None = None,
    show_legend: bool = True,
    color_by: Literal[
        "paint_a", "paint_b", "paint_c"
    ] = "paint_c",
    cguide: dict | None = None,
    breaks: list | dict | None = None,
    labels: list | dict | None = None,
    lablim: int | None = None,
    format: str | None = None,
) -> LayerSpec | FeatureSpec

Display an image array, as lets_plot geom_imshow.

Parameters:

  • image_data (ndarray) –

    2D greyscale image (height x width), or 3D RGB / RGBA (height x width x 3|4). Float RGB(A) values are in 0..1, integer ones in 0..255.

  • cmap (str or list of str, default: None ) –

    Greyscale only: a matplotlib color map name (needs palettable) or a list of colors (hex, rgb() or rgba()). Default: shades of grey.

  • norm (bool, default: True ) –

    Greyscale only: stretch vmin..vmax to the full luminance range. False keeps the values as luminance (clipped to 0..255).

  • alpha (float, default: None ) –

    Image opacity in 0..1.

  • vmin (float, default: None ) –

    Greyscale only: the data range the color map covers; the image's min / max by default.

  • vmax (float, default: None ) –

    Greyscale only: the data range the color map covers; the image's min / max by default.

  • extent (list of 4 float, default: None ) –

    [x0, x1, y0, y1] of the image box in data units. Default: pixel centers at integers ([-0.5, width - 0.5, -0.5, height - 0.5]). x0 > x1 or y0 > y1 flips the image.

  • compression (int, default: None ) –

    PNG compression level 0..9.

  • show_legend (bool, default: True ) –

    Greyscale only: show a colorbar.

  • color_by ((paint_a, paint_b, paint_c), default: "paint_a" ) –

    The aesthetic the colorbar uses.

  • cguide (FeatureSpec, default: None ) –

    Greyscale only: the colorbar, a guide_colorbar() spec.

  • breaks (list of float, default: None ) –

    Greyscale only: colorbar ticks.

  • labels (list of str, default: None ) –

    Greyscale only: one label per break.

  • lablim (int, default: None ) –

    Maximum label length in characters; longer labels are cut.

  • format (str, default: None ) –

    Label format of the colorbar, e.g. ".2f".

Returns:

  • LayerSpec or FeatureSpec –

    The geom_image layer, plus its color scale for a greyscale image with a legend.

Raises:

  • ValueError –

    When image_data is not a 2D/3D ndarray, alpha or compression is out of range, vmin > vmax, cmap is invalid, or extent is not 4 numbers.

Examples:

>>> import numpy as np
>>> from ggrust import ggplot, geom_imshow
>>> image = np.random.default_rng(0).random((20, 30))
>>> plot = ggplot() + geom_imshow(image, cmap=["#000000", "#ff8800"])