@@ -359,6 +359,27 @@ def test_BoundaryNorm():
359359 assert_array_equal (cmshould (mynorm (x )), cmref (refnorm (x )))
360360
361361
362+ def test_CenteredNorm ():
363+ # Assert equivalence to symmetrical Normalize.
364+ x = np .random .normal (size = 100 )
365+ x_maxabs = np .max (np .abs (x ))
366+ norm_ref = mcolors .Normalize (vmin = - x_maxabs , vmax = x_maxabs )
367+ norm = mcolors .CenteredNorm ()
368+ assert_array_almost_equal (norm_ref (x ), norm (x ))
369+ # Check that vcenter is in the center of vmin and vmax
370+ # when vcenter is set.
371+ vcenter = int (np .random .normal (scale = 50 ))
372+ norm = mcolors .CenteredNorm (vcenter = vcenter )
373+ norm .autoscale_None ([1 , 2 ])
374+ assert norm .vmax + norm .vmin == 2 * vcenter
375+ # Check that halfrange input works correctly.
376+ x = np .random .normal (size = 10 )
377+ norm = mcolors .CenteredNorm (vcenter = 0.5 , halfrange = 0.5 )
378+ assert_array_almost_equal (x , norm (x ))
379+ norm = mcolors .CenteredNorm (vcenter = 1 , halfrange = 1 )
380+ assert_array_almost_equal (x , 2 * norm (x ))
381+
382+
362383@pytest .mark .parametrize ("vmin,vmax" , [[- 1 , 2 ], [3 , 1 ]])
363384def test_lognorm_invalid (vmin , vmax ):
364385 # Check that invalid limits in LogNorm error
0 commit comments