Skip to content

scale_fill_stepsn

scale_fill_stepsn(
    colors: Sequence[Color] | None = None,
    name: str | None = None,
    breaks: Breaks | None = None,
    labels: Labels | None = None,
    limits: Limits | None = None,
    n_breaks: int | None = None,
    nice_breaks: bool = True,
    right: bool = True,
    show_limits: bool = False,
    oob: Oob = "squish",
    na_value: Color | Number | None = None,
    guide: Guide | None = None,
    trans: Transform | None = None,
    format: str | None = None,
) -> FeatureSpec

Map fill to binned colors of an n-color gradient (ggplot2).

Binned like scale_fill_steps, colored like scale_fill_gradientn.

Parameters:

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

    Two or more colors spread evenly over the range.

  • name (str, default: None ) –

    Legend title.

  • breaks (list, default: None ) –

    Bin edges inside the data range (data units). Default: about n_breaks generated ones.

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

    One label per break (a dict maps breaks to labels).

  • limits (list, default: None ) –

    [low, high] range of the bins. Without limits or breaks, the ends move out so the end bins are as wide as the others (ggplot2).

  • n_breaks (int, default: None ) –

    How many breaks to aim for (default 5).

  • nice_breaks (bool, default: True ) –

    Round break values; False spaces n_breaks breaks evenly over the range.

  • right (bool, default: True ) –

    Bins are closed on the right: a value on a break joins the bin below it.

  • show_limits (bool, default: False ) –

    Also label the two ends of the colorbar.

  • oob ((squish, censor), default: "squish" ) –

    What data outside limits maps to: the end bins ("squish") or na_value ("censor").

  • na_value (str, default: None ) –

    Color of missing data.

  • guide (str or FeatureSpec, default: None ) –

    "colorbar" (default, drawn as steps), "legend", "none", or a guide_colorbar() / guide_legend() spec.

  • trans (str, default: None ) –

    Transformation of the data, as in scale_color_gradient; breaks are generated in transformed units.

  • format (str, default: None ) –

    Label format, e.g. ".1f" or ",". labels take precedence.

Returns:

  • FeatureSpec –

    The scale.

Raises:

  • SpecError –

    If oob is not "squish" or "censor".

Examples:

>>> from ggrust import *
>>> data = {"x": [1, 2, 3] * 3, "y": [1] * 3 + [2] * 3 + [3] * 3,
...         "change": [-3, -1, 0, -2, 0, 2, 0, 1, 4]}
>>> plot = ggplot(data, aes("x", "y", fill="change")) + geom_tile()
>>> plot = plot + scale_fill_stepsn(colors=["navy", "gold", "darkred"])

Ask for more bins with n_breaks:

>>> base = ggplot(data, aes("x", "y", fill="change")) + geom_tile()
>>> plot = base + scale_fill_stepsn(colors=["navy", "gold", "darkred"], n_breaks=8)

Ask for more bins with n_breaks