scale_gradient ¶
scale_gradient(
aesthetic: str | Sequence[str],
*,
low: Color | None = None,
high: Color | None = None,
name: str | None = None,
breaks: Breaks | None = None,
labels: Labels | None = None,
lablim: int | None = None,
limits: Limits | None = None,
oob: Oob | None = None,
rescaler: Rescaler | None = None,
na_value: Color | None = None,
guide: Guide | None = None,
trans: Transform | None = None,
format: str | None = None,
) -> FeatureSpec
Map color aesthetics to a two-color gradient (in LAB space).
Parameters:
-
aesthetic(str or list of str) –The color aesthetic(s), e.g.
"fill"or["color", "fill"]. -
low(str, default:"#132B43", "#56B1F7") –Colors at the low and high end of the data.
-
high(str, default:"#132B43", "#56B1F7") –Colors at the low and high end of the data.
-
name(str, default:None) –Legend title.
-
breaks(list or dict, default:None) –Values that get a colorbar tick (a dict maps labels to breaks).
-
labels(list of str or dict, default:None) –One label per break (a dict maps breaks to labels).
-
lablim(int, default:None) –Ignored on continuous scales, with a warning, as in lets-plot.
-
limits(list, default:None) –[low, high]data range. Data outside the limits getsna_value. -
oob((censor, squish), default:"censor") –What data outside
limitsmaps to. Not in lets-plot (ggplot2oob). -
rescaler(callable, default:None) –rescaler(x, to, from_)maps the data to(0, 1)before the palette. Not in lets-plot (ggplot2rescaler). -
na_value(str, default:None) –Color drawn for missing data and data outside
limits. -
guide(str or FeatureSpec, default:None) –"colorbar","legend","none", or a guide spec. -
trans(str, default:None) –Transformation of the data, e.g.
"log10"or"sqrt". -
format(str, default:None) –Label format, e.g.
".1f".labelstake precedence.
Returns:
-
FeatureSpec–The scale, or a
FeatureSpecArrayof one scale per aesthetic for a list.
Raises:
-
UnsupportedValueError–If
aestheticis not a string or a list of strings. -
SpecError–If
aestheticis an empty list.
Examples:
>>> from ggrust import *
>>> data = {"x": [1, 2, 3, 4, 5], "y": [3, 1, 4, 1, 5], "change": [-2, -1, 0, 1, 2]}
>>> plot = ggplot(data, aes("x", "y", color="change", fill="change"))
>>> plot = plot + geom_point(shape=21, size=10, alpha=0.4)
>>> plot = plot + scale_gradient(["color", "fill"], low="gold", high="darkred")