MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_CenteredNorm

Function test_CenteredNorm

lib/matplotlib/tests/test_colors.py:429–496  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

427
428
429def test_CenteredNorm():
430 np.random.seed(0)
431
432 # Assert equivalence to symmetrical Normalize.
433 x = np.random.normal(size=100)
434 x_maxabs = np.max(np.abs(x))
435 norm_ref = mcolors.Normalize(vmin=-x_maxabs, vmax=x_maxabs)
436 norm = mcolors.CenteredNorm()
437 assert_array_almost_equal(norm_ref(x), norm(x))
438
439 # Check that vcenter is in the center of vmin and vmax
440 # when vcenter is set.
441 vcenter = int(np.random.normal(scale=50))
442 norm = mcolors.CenteredNorm(vcenter=vcenter)
443 norm.autoscale_None([1, 2])
444 assert norm.vmax + norm.vmin == 2 * vcenter
445
446 # Check that halfrange can be set without setting vcenter and that it is
447 # not reset through autoscale_None.
448 norm = mcolors.CenteredNorm(halfrange=1.0)
449 norm.autoscale_None([1, 3000])
450 assert norm.halfrange == 1.0
451
452 # Check that halfrange input works correctly.
453 x = np.random.normal(size=10)
454 norm = mcolors.CenteredNorm(vcenter=0.5, halfrange=0.5)
455 assert_array_almost_equal(x, norm(x))
456 norm = mcolors.CenteredNorm(vcenter=1, halfrange=1)
457 assert_array_almost_equal(x, 2 * norm(x))
458
459 # Check that halfrange input works correctly and use setters.
460 norm = mcolors.CenteredNorm()
461 norm.vcenter = 2
462 norm.halfrange = 2
463 assert_array_almost_equal(x, 4 * norm(x))
464
465 # Check that prior to adding data, setting halfrange first has same effect.
466 norm = mcolors.CenteredNorm()
467 norm.halfrange = 2
468 norm.vcenter = 2
469 assert_array_almost_equal(x, 4 * norm(x))
470
471 # Check that manual change of vcenter adjusts halfrange accordingly.
472 norm = mcolors.CenteredNorm()
473 assert norm.vcenter == 0
474 # add data
475 norm(np.linspace(-1.0, 0.0, 10))
476 assert norm.vmax == 1.0
477 assert norm.halfrange == 1.0
478 # set vcenter to 1, which should move the center but leave the
479 # halfrange unchanged
480 norm.vcenter = 1
481 assert norm.vmin == 0
482 assert norm.vmax == 2
483 assert norm.halfrange == 1
484
485 # Check setting vmin directly updates the halfrange and vmax, but
486 # leaves vcenter alone

Callers

nothing calls this directly

Calls 3

autoscale_NoneMethod · 0.95
normFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…