@@ -2538,22 +2538,22 @@ class SegmentedNorm(mcolors.Normalize):
2538
2538
Normalizer that scales data linearly with respect to the
2539
2539
interpolated index in an arbitrary monotonic level sequence.
2540
2540
"""
2541
- def __init__ (self , levels , vmin = None , vmax = None , clip = False ):
2541
+ def __init__ (self , levels , vcenter = None , vmin = None , vmax = None , clip = None , fair = True ): # noqa: E501
2542
2542
"""
2543
2543
Parameters
2544
2544
----------
2545
2545
levels : sequence of float
2546
- The level boundaries. Must be monotonically increasing
2547
- or decreasing.
2546
+ The level boundaries. Must be monotonically increasing or decreasing.
2547
+ vcenter : float, default: None
2548
+ The central colormap value. Default is to omit this.
2548
2549
vmin : float, optional
2549
- Ignored but included for consistency with other normalizers.
2550
- Set to the minimum of `levels`.
2550
+ Ignored but included for consistency. Set to ``min(levels)``.
2551
2551
vmax : float, optional
2552
- Ignored but included for consistency with other normalizers.
2553
- Set to the minimum of `levels`.
2552
+ Ignored but included for consistency. Set to ``max(levels)``.
2554
2553
clip : bool, optional
2555
- Whether to clip values falling outside of the minimum
2556
- and maximum of `levels`.
2554
+ Whether to clip values falling outside of `vmin` and `vmax`.
2555
+ fair : bool, optional
2556
+ Whether to use fair scaling. See `DivergingNorm`.
2557
2557
2558
2558
See also
2559
2559
--------
@@ -2587,7 +2587,21 @@ def __init__(self, levels, vmin=None, vmax=None, clip=False):
2587
2587
dest = np .linspace (0 , 1 , len (levels ))
2588
2588
vmin = np .min (levels )
2589
2589
vmax = np .max (levels )
2590
+ if vcenter is not None :
2591
+ center = _interpolate_extrapolate_vector (vcenter , levels , dest )
2592
+ idxs , = np .where (np .isclose (vcenter , levels ))
2593
+ if fair :
2594
+ delta = center - 0.5
2595
+ delta = max (- (dest [0 ] - delta ), dest [- 1 ] - delta - 1 )
2596
+ dest = (dest - center ) / (1 + 2 * delta ) + 0.5
2597
+ elif idxs .size and idxs [0 ] > 0 and idxs [0 ] < len (levels ) - 1 :
2598
+ dest1 = np .linspace (0 , 0.5 , idxs [0 ] + 1 )
2599
+ dest2 = np .linspace (0.5 , 1 , len (levels ) - idxs [0 ])
2600
+ dest = np .append (dest1 , dest2 [1 :])
2601
+ else :
2602
+ raise ValueError (f'Center { vcenter } not in level list { levels } .' )
2590
2603
super ().__init__ (vmin = vmin , vmax = vmax , clip = clip )
2604
+ self .vcenter = vcenter # used for DiscreteNorm
2591
2605
self ._x = self .boundaries = levels # 'boundaries' are used in PlotAxes
2592
2606
self ._y = dest
2593
2607
@@ -2636,26 +2650,24 @@ class DivergingNorm(mcolors.Normalize):
2636
2650
def __str__ (self ):
2637
2651
return type (self ).__name__ + f'(center={ self .vcenter !r} )'
2638
2652
2639
- def __init__ (
2640
- self , vcenter = 0 , vmin = None , vmax = None , fair = True , clip = None
2641
- ):
2653
+ def __init__ (self , vcenter = 0 , vmin = None , vmax = None , clip = None , fair = True ):
2642
2654
"""
2643
2655
Parameters
2644
2656
----------
2645
2657
vcenter : float, default: 0
2646
- The data value corresponding to the central colormap position .
2658
+ The central data value .
2647
2659
vmin : float, optional
2648
2660
The minimum data value.
2649
2661
vmax : float, optional
2650
2662
The maximum data value.
2663
+ clip : bool, optional
2664
+ Whether to clip values falling outside of `vmin` and `vmax`.
2651
2665
fair : bool, optional
2652
2666
If ``True`` (default), the speeds of the color gradations on either side
2653
2667
of the center point are equal, but colormap colors may be omitted. If
2654
2668
``False``, all colormap colors are included, but the color gradations on
2655
2669
one side may be faster than the other side. ``False`` should be used with
2656
2670
great care, as it may result in a misleading interpretation of your data.
2657
- clip : bool, optional
2658
- Whether to clip values falling outside of `vmin` and `vmax`.
2659
2671
2660
2672
See also
2661
2673
--------
0 commit comments