annotate_bands

annotate_bands(
    plot,
    bands,
    axis='x',
    at=None,
    label_offset=None,
    labels=True,
    text_colour=None,
    text_size=None,
    linewidth=1,
)

Annotate a plot with labelled decision bands.

Adds the BAD / OK / GOOD style decision markers survey charts carry: for each band a thin coloured marker line runs along one axis, with a bold centred label, so a reader instantly sees where “good” and “bad” lie. Supply a band spec (a data frame with from, to, label and optional colour, or one of the bands_rating_3() presets), the axis the bands run along, and at: the position on the opposite axis for the marker line (usually the top of the panel; inferred from the plot when omitted).

Parameters

Name Type Description Default
plot plotnine.ggplot A chart. required
bands pandas.DataFrame or dict A band specification. required
axis str Which axis the bands run along: “x” (default) or “y”. 'x'
at float Position on the opposite axis at which to draw the marker line and labels. If None, the top of the plot’s panel range. None
label_offset float Distance to nudge labels away from the marker line, in data units of the opposite axis. None (default) is 4% of the opposite axis range. None
labels bool Whether to draw the band labels. Default True. True
text_colour str Label colour; None (default) uses each band’s own colour. None
text_size float Label size in points; None (default) matches the theme’s base font size (11 pt). None
linewidth float Marker line width. Default 1. 1

Returns

Name Type Description
plotnine.ggplot The chart with the band layers added.

See Also

mark_value, bands_rating_3

Examples

>>> model = ipm_model(podracing_survey, "nps_value", "ratings_")
>>> annotate_bands(plot_ipm(model), bands_rating_3(), axis="x")