scale_y_pct

scale_y_pct(values=None, unit=PCT_UNIT, pad=0, max=None, labels=True, **kwargs)

Continuous y-scale capped at a nice maximum, with percent labels.

A thin wrapper around plotnine’s scale_y_continuous() that sets the upper limit with nice_max() and, by default, formats the axis as percentages. The upper limit is chosen in order of precedence: a fixed max; otherwise nice_max() of values; otherwise left to plotnine. plot_bars() calls this for you, reading unit and max from the pct_axis_unit / pct_axis_max options.

Parameters

Name Type Description Default
values list of numbers Values that set the axis ceiling, usually the column being plotted. None
unit Passed to nice_max(). PCT_UNIT
pad Passed to nice_max(). PCT_UNIT
max float Fixed upper limit (e.g. 100), overriding the dynamic ceiling. None
labels bool or callable True (default) formats breaks as “42%”; False hides the axis labels; a function is used as the labels directly. True
**kwargs Passed to plotnine’s scale_y_continuous(). {}

Returns

Name Type Description
plotnine scale A continuous y scale.

See Also

nice_max, label_pct, plot_bars

Examples

>>> from plotnine import ggplot, aes, geom_col
>>> df = calc_percentage(podracing_survey, "demo_gender")
>>> ggplot(df, aes("demo_gender", "pct")) + geom_col() + scale_y_pct(df["pct"])