Use some heuristics to set good defaults for colorbar and range. Parameters ---------- plot_data : Numpy array Doesn't handle xarray objects Returns ------- cmap_params : dict Use depends on the type of the plotting function
(
plot_data,
vmin=None,
vmax=None,
cmap=None,
center=None,
robust=False,
extend=None,
levels=None,
filled=True,
norm=None,
_is_facetgrid=False,
)
| 159 | |
| 160 | |
| 161 | def _determine_cmap_params( |
| 162 | plot_data, |
| 163 | vmin=None, |
| 164 | vmax=None, |
| 165 | cmap=None, |
| 166 | center=None, |
| 167 | robust=False, |
| 168 | extend=None, |
| 169 | levels=None, |
| 170 | filled=True, |
| 171 | norm=None, |
| 172 | _is_facetgrid=False, |
| 173 | ): |
| 174 | """ |
| 175 | Use some heuristics to set good defaults for colorbar and range. |
| 176 | |
| 177 | Parameters |
| 178 | ---------- |
| 179 | plot_data : Numpy array |
| 180 | Doesn't handle xarray objects |
| 181 | |
| 182 | Returns |
| 183 | ------- |
| 184 | cmap_params : dict |
| 185 | Use depends on the type of the plotting function |
| 186 | """ |
| 187 | if TYPE_CHECKING: |
| 188 | import matplotlib as mpl |
| 189 | else: |
| 190 | mpl = attempt_import("matplotlib") |
| 191 | |
| 192 | if plot_data.dtype.kind == "m": |
| 193 | unit, _ = np.datetime_data(plot_data.dtype) |
| 194 | zero = np.timedelta64(0, unit) |
| 195 | elif plot_data.dtype.kind == "M": |
| 196 | unit, _ = np.datetime_data(plot_data.dtype) |
| 197 | zero = np.datetime64(0, unit) |
| 198 | else: |
| 199 | zero = 0.0 |
| 200 | |
| 201 | if isinstance(levels, Iterable): |
| 202 | levels = sorted(levels) |
| 203 | |
| 204 | calc_data = np.ravel(plot_data[np.isfinite(plot_data)]) |
| 205 | |
| 206 | # Handle all-NaN input data gracefully |
| 207 | if calc_data.size == 0: |
| 208 | # Arbitrary default for when all values are NaN |
| 209 | calc_data = np.array(zero) |
| 210 | |
| 211 | # Setting center=False prevents a divergent cmap |
| 212 | possibly_divergent = center is not False |
| 213 | |
| 214 | # Set center to 0 so math below makes sense but remember its state |
| 215 | center_is_none = False |
| 216 | if center is None: |
| 217 | center = zero |
| 218 | center_is_none = True |
searching dependent graphs…