airbornegeo.choose_colormap

Contents

airbornegeo.choose_colormap#

choose_colormap(data, robust=True)[source]#

Choose an appropriate colormap and color limits for a set of values.

If 0 lies strictly between the 25th and 75th percentiles of the data, return a diverging colormap (‘RdBu’) centered on zero with symmetric (robust) limits. Otherwise, return a sequential colormap (‘viridis’) spanning the (robust) data range. NaNs are ignored.

Parameters:
  • data (ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]] | Series) – The values to be plotted. Must contain at least one finite value.

  • robust (bool) – Use percentiles (98 for the diverging case, 2 and 98 for the sequential case) instead of the full data range, so outliers don’t dominate the color scale, by default True.

Returns:

The colormap name, and the lower and upper color limits.

Return type:

tuple[str, float, float]

Examples

>>> choose_colormap([-1.0, 0.0, 1.0], robust=False)
('RdBu', -1.0, 1.0)
>>> choose_colormap([10.0, 15.0, 20.0], robust=False)
('viridis', 10.0, 20.0)