A class which, when called, maps values within the interval ``[vmin, vmax]`` linearly to the interval ``[0.0, 1.0]``. The mapping of values outside ``[vmin, vmax]`` depends on *clip*. Examples -------- :: x = [-2, -1, 0, 1, 2] norm = mpl.colors.Normalize(v
| 2395 | |
| 2396 | |
| 2397 | class Normalize(Norm): |
| 2398 | """ |
| 2399 | A class which, when called, maps values within the interval |
| 2400 | ``[vmin, vmax]`` linearly to the interval ``[0.0, 1.0]``. The mapping of |
| 2401 | values outside ``[vmin, vmax]`` depends on *clip*. |
| 2402 | |
| 2403 | Examples |
| 2404 | -------- |
| 2405 | :: |
| 2406 | |
| 2407 | x = [-2, -1, 0, 1, 2] |
| 2408 | |
| 2409 | norm = mpl.colors.Normalize(vmin=-1, vmax=1, clip=False) |
| 2410 | norm(x) # [-0.5, 0., 0.5, 1., 1.5] |
| 2411 | norm = mpl.colors.Normalize(vmin=-1, vmax=1, clip=True) |
| 2412 | norm(x) # [0., 0., 0.5, 1., 1.] |
| 2413 | |
| 2414 | See Also |
| 2415 | -------- |
| 2416 | :ref:`colormapnorms` |
| 2417 | """ |
| 2418 | |
| 2419 | def __init__(self, vmin=None, vmax=None, clip=False): |
| 2420 | """ |
| 2421 | Parameters |
| 2422 | ---------- |
| 2423 | vmin, vmax : float or None |
| 2424 | Values within the range ``[vmin, vmax]`` from the input data will be |
| 2425 | linearly mapped to ``[0, 1]``. If either *vmin* or *vmax* is not |
| 2426 | provided, they default to the minimum and maximum values of the input, |
| 2427 | respectively. |
| 2428 | |
| 2429 | clip : bool, default: False |
| 2430 | Determines the behavior for mapping values outside the range |
| 2431 | ``[vmin, vmax]``. |
| 2432 | |
| 2433 | If clipping is off, values outside the range ``[vmin, vmax]`` are |
| 2434 | also transformed, resulting in values outside ``[0, 1]``. This |
| 2435 | behavior is usually desirable, as colormaps can mark these *under* |
| 2436 | and *over* values with specific colors. |
| 2437 | |
| 2438 | If clipping is on, values below *vmin* are mapped to 0 and values |
| 2439 | above *vmax* are mapped to 1. Such values become indistinguishable |
| 2440 | from regular boundary values, which may cause misinterpretation of |
| 2441 | the data. |
| 2442 | |
| 2443 | Notes |
| 2444 | ----- |
| 2445 | If ``vmin == vmax``, input data will be mapped to 0. |
| 2446 | """ |
| 2447 | super().__init__() |
| 2448 | self._vmin = _sanitize_extrema(vmin) |
| 2449 | self._vmax = _sanitize_extrema(vmax) |
| 2450 | self._clip = clip |
| 2451 | self._scale = None |
| 2452 | |
| 2453 | @property |
| 2454 | def vmin(self): |
no outgoing calls
searching dependent graphs…