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

Function test_colorbar_renorm

lib/matplotlib/tests/test_colorbar.py:596–623  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

594
595
596def test_colorbar_renorm():
597 x, y = np.ogrid[-4:4:31j, -4:4:31j]
598 z = 120000*np.exp(-x**2 - y**2)
599
600 fig, ax = plt.subplots()
601 im = ax.imshow(z)
602 cbar = fig.colorbar(im)
603 np.testing.assert_allclose(cbar.ax.yaxis.get_majorticklocs(),
604 np.arange(0, 120000.1, 20000))
605
606 cbar.set_ticks([1, 2, 3])
607 assert isinstance(cbar.locator, FixedLocator)
608
609 norm = LogNorm(z.min(), z.max())
610 im.set_norm(norm)
611 np.testing.assert_allclose(cbar.ax.yaxis.get_majorticklocs(),
612 np.logspace(-9, 6, 16))
613 # note that set_norm removes the FixedLocator...
614 assert np.isclose(cbar.vmin, z.min())
615 cbar.set_ticks([1, 2, 3])
616 assert isinstance(cbar.locator, FixedLocator)
617 np.testing.assert_allclose(cbar.ax.yaxis.get_majorticklocs(),
618 [1.0, 2.0, 3.0])
619
620 norm = LogNorm(z.min() * 1000, z.max() * 1000)
621 im.set_norm(norm)
622 assert np.isclose(cbar.vmin, z.min() * 1000)
623 assert np.isclose(cbar.vmax, z.max() * 1000)
624
625
626@pytest.mark.parametrize('fmt', ['%4.2e', '{x:.2e}'])

Callers

nothing calls this directly

Calls 9

imshowMethod · 0.80
get_majorticklocsMethod · 0.80
minMethod · 0.80
maxMethod · 0.80
iscloseMethod · 0.80
subplotsMethod · 0.45
colorbarMethod · 0.45
set_ticksMethod · 0.45
set_normMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…