verde.maxabs#
- verde.maxabs(*args, nan=True, percentile=100)[source]#
Calculate the maximum absolute value of the given array(s).
Use this to set the limits of your colorbars and center them on zero.
- Parameters:
- args
One or more arrays. If more than one are given, a single maximum will be calculated across all arrays.
- nanbool,
optional If True, will use the
nanversion of numpy functions to ignore NaNs.- percentile
float,optional Instead of return the maximum absolute value, return a given percentile of the absolute values. Must be between 0 and 100. A value of 100 (default) will give the maximum absolute value, while a value of 50 will give the median of the absolute values.
- Returns:
- maxabs
float The maximum (or percentile) absolute value across all arrays.
- maxabs
Examples
>>> result = maxabs((1, -10, 25, 2, 3)) >>> float(result) 25.0 >>> result = maxabs( ... (1, -10.5, 25, 2), (0.1, 100, -500), (-200, -300, -0.1, -499) ... ) >>> float(result) 500.0
If the array contains NaNs, we’ll use the
nanversion of of the numpy functions by default. You can turn this off through the nan argument.>>> import numpy as np >>> result = maxabs((1, -10, 25, 2, 3, np.nan)) >>> float(result) 25.0 >>> result = maxabs((1, -10, 25, 2, 3, np.nan), nan=False) >>> float(result) nan
If a more robust statistic is desired, you can use
percentileto get the value at a given percentile instead of the maximum.>>> result = maxabs((1, -10, 25, 2, 3), percentile=95) >>> float(result) 21.99 >>> result = maxabs((1, -10, 25, 2, 3), percentile=100) >>> float(result) 25.0