guide_axis ¶
guide_axis(
title: str | None = None,
*,
cap: Literal["none", "both", "upper", "lower"]
| bool
| None = None,
) -> FeatureSpec
Axis guide for a position scale, with axis capping (ggplot2 guide_axis).
cap cuts the axis line back to the outermost breaks. It shows only where the
theme draws an axis line (theme_classic(), or
theme(axis_line=element_line())); ticks, labels and the grid are unchanged.
Parameters:
-
title(str, default:None) –Axis title, as
labs(x=...). -
cap((none, both, upper, lower), default:"none") –Which ends of the axis line stop at the outermost break:
"both", the right (top) end only ("upper"), the left (bottom) end only ("lower"), or none.Trueis"both",Falseis"none". The ends are visual:"upper"is the right end also on a reversed scale. Undercoord_flip(),guides(x=...)caps the axis drawn horizontally (as ggplot2); a scale's ownguide=caps that scale's axis.
Returns:
-
FeatureSpec–Guide specification for
guides(x=...)/guides(y=...)or a discrete position scale'sguide=.
Raises:
-
SpecError–If
capis an unknown name. -
UnsupportedValueError–If
capis neither a name nor a boolean.
Examples:
>>> from ggrust import *
>>> data = {"age": [1, 3, 5, 7, 2, 4, 6, 8, 3, 9],
... "weight": [4, 6, 6, 7, 8, 12, 14, 15, 2, 3]}
>>> plot = (
... ggplot(data, aes("age", "weight"))
... + geom_point()
... + theme_classic()
... + guides(x=guide_axis(cap="both"), y=guide_axis(cap="upper"))
... )
A guide can also carry the axis title:
>>> plot = (
... ggplot(data, aes("age", "weight"))
... + geom_point()
... + theme_classic()
... + guides(x=guide_axis("Age (years)", cap="lower"), y=guide_axis("Weight", cap=True))
... )
A guide can also carry the axis title