scale_fill_steps ¶
scale_fill_steps(
low: Color | None = None,
high: 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 a two-color gradient (ggplot2).
Each value takes the gradient's color at the middle of its bin, so the colors step from bin to bin and the colorbar shows one flat block per bin.
Parameters:
-
low(str, default:"#132B43", "#56B1F7") –Colors of the lowest and highest bin.
-
high(str, default:"#132B43", "#56B1F7") –Colors of the lowest and highest bin.
-
name(str, default:None) –Legend title.
-
breaks(list, default:None) –Bin edges inside the data range (data units). Default: about
n_breaksgenerated 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 orbreaks, 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_breaksbreaks 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
limitsmaps to: the end bins ("squish") orna_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 aguide_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",".labelstake precedence.
Returns:
-
FeatureSpec–The scale.
Raises:
-
SpecError–If
oobis 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_steps(low="lightyellow", high="firebrick")
Set the bin edges with breaks and label the ends with show_limits:
>>> base = ggplot(data, aes("x", "y", fill="change")) + geom_tile()
>>> plot = base + scale_fill_steps(
... low="lightyellow", high="firebrick", breaks=[-2, 0, 2], show_limits=True
... )
Set the bin edges with breaks and label the ends with show_limits