scale_color_stepsn ¶
scale_color_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 color to binned colors of an n-color gradient (ggplot2).
Binned like scale_color_steps, colored like scale_color_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_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", color="change")) + geom_point(size=12)
>>> plot = plot + scale_color_stepsn(colors=["navy", "gold", "darkred"])
Ask for more bins with n_breaks:
>>> base = ggplot(data, aes("x", "y", color="change")) + geom_point(size=12)
>>> plot = base + scale_color_stepsn(colors=["navy", "gold", "darkred"], n_breaks=8)
Ask for more bins with n_breaks