Normalize symmetrical data around a center (0 by default). Unlike `TwoSlopeNorm`, `CenteredNorm` applies an equal rate of change around the center. Useful when mapping symmetrical data around a conceptual center e.g., data that range from -2 to 4, with 0 as
(self, vcenter=0, halfrange=None, clip=False)
| 2714 | |
| 2715 | class CenteredNorm(Normalize): |
| 2716 | def __init__(self, vcenter=0, halfrange=None, clip=False): |
| 2717 | """ |
| 2718 | Normalize symmetrical data around a center (0 by default). |
| 2719 | |
| 2720 | Unlike `TwoSlopeNorm`, `CenteredNorm` applies an equal rate of change |
| 2721 | around the center. |
| 2722 | |
| 2723 | Useful when mapping symmetrical data around a conceptual center |
| 2724 | e.g., data that range from -2 to 4, with 0 as the midpoint, and |
| 2725 | with equal rates of change around that midpoint. |
| 2726 | |
| 2727 | Parameters |
| 2728 | ---------- |
| 2729 | vcenter : float, default: 0 |
| 2730 | The data value that defines ``0.5`` in the normalization. |
| 2731 | halfrange : float, optional |
| 2732 | The range of data values that defines a range of ``0.5`` in the |
| 2733 | normalization, so that *vcenter* - *halfrange* is ``0.0`` and |
| 2734 | *vcenter* + *halfrange* is ``1.0`` in the normalization. |
| 2735 | Defaults to the largest absolute difference to *vcenter* for |
| 2736 | the values in the dataset. |
| 2737 | clip : bool, default: False |
| 2738 | Determines the behavior for mapping values outside the range |
| 2739 | ``[vmin, vmax]``. |
| 2740 | |
| 2741 | If clipping is off, values outside the range ``[vmin, vmax]`` are |
| 2742 | also transformed, resulting in values outside ``[0, 1]``. This |
| 2743 | behavior is usually desirable, as colormaps can mark these *under* |
| 2744 | and *over* values with specific colors. |
| 2745 | |
| 2746 | If clipping is on, values below *vmin* are mapped to 0 and values |
| 2747 | above *vmax* are mapped to 1. Such values become indistinguishable |
| 2748 | from regular boundary values, which may cause misinterpretation of |
| 2749 | the data. |
| 2750 | |
| 2751 | Examples |
| 2752 | -------- |
| 2753 | This maps data values -2 to 0.25, 0 to 0.5, and 4 to 1.0 |
| 2754 | (assuming equal rates of change above and below 0.0): |
| 2755 | |
| 2756 | >>> import matplotlib.colors as mcolors |
| 2757 | >>> norm = mcolors.CenteredNorm(halfrange=4.0) |
| 2758 | >>> data = [-2., 0., 4.] |
| 2759 | >>> norm(data) |
| 2760 | array([0.25, 0.5 , 1. ]) |
| 2761 | """ |
| 2762 | super().__init__(vmin=None, vmax=None, clip=clip) |
| 2763 | self._vcenter = vcenter |
| 2764 | # calling the halfrange setter to set vmin and vmax |
| 2765 | self.halfrange = halfrange |
| 2766 | |
| 2767 | def autoscale(self, A): |
| 2768 | """ |