verde.minmax#
- verde.minmax(*args, nan=True, min_percentile=0, max_percentile=100)[source]#
Calculate the minimum and maximum values of the given array(s).
Use this to set the limits of your colorbars for non-diverging data.
- Parameters:
- args
One or more arrays. If more than one are given, a minimum and maximum will be calculated across all arrays.
- nanbool,
optional If True, will use the
nanversion of numpy functions to ignore NaNs.- min_percentile
float Return the supplied percentile (0 to 100) instead of the minimum value of the arrays. Defaults to 0, giving the minimum value.
- max_percentile
float Return the supplied percentile (0 to 100) instead of the maximum value of the arrays. Defaults to 100, giving the maximum value.
- Returns:
- min, max
float The minimum and maximum (or percentile) values across all arrays.
- min, max
Examples
>>> result = minmax((1, -10, 25, 2, 3)) >>> tuple(map(float, result)) (-10.0, 25.0) >>> result = minmax( ... (1, -10.5, 25, 2), (0.1, 100, -500), (-200, -300, -0.1, -499) ... ) >>> tuple(map(float, result)) (-500.0, 100.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 = minmax((1, -10, 25, 2, 3, np.nan)) >>> tuple(map(float, result)) (-10.0, 25.0) >>> result = minmax((1, -10, 25, 2, 3, np.nan), nan=False) >>> tuple(map(float, result)) (nan, nan)
If a more robust statistic is desired, you can use
min_percentileand ormax_percentileto get the values at given percentiles instead of the minimum and maximum.>>> import numpy as np >>> result = minmax( ... (1, -10, 25, 2, 3), min_percentile=2, max_percentile=98 ... ) >>> tuple(map(float, result)) (-9.12, 23.24) >>> result = minmax( ... (1, -10, 25, 2, 3), min_percentile=0, max_percentile=100 ... ) >>> tuple(map(float, result)) (-10.0, 25.0)