nice_max
nice_max(x, unit=PCT_UNIT, pad=0)Round an axis maximum up to a “nice” value.
Picks the next multiple of unit strictly above max(x): the dynamic y-axis trick survey reports use, where bar charts get a tidy ceiling in units of 25 (percentages) or 5 (NPS counts) so data labels never collide with the top of the panel. The ceiling is (floor(max(x) / unit) + 1) * unit + pad, so an exact multiple still advances (nice_max(75) is 100, not 75). An all-missing input returns missing. This is the engine behind scale_y_pct() and the percentage plot wrappers.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| x | number or list of numbers | Values; missing ones are ignored. | required |
| unit | float | Size of the rounding step, e.g. 25 for percentages, 5 for smaller counts. Must be positive. | PCT_UNIT |
| pad | float | Extra headroom added to the result, in the units of x. Default 0. |
0 |
Returns
| Name | Type | Description |
|---|---|---|
| float | The padded, rounded-up ceiling, or NaN when x is empty or all missing. |
See Also
scale_y_pct, label_pct
Examples
>>> nice_max([12, 63, 40])
>>> nice_max(80, unit=25)
>>> nice_max(75, unit=25)
>>> nice_max([8, 17], unit=5, pad=10)