()
| 594 | |
| 595 | |
| 596 | def 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}']) |
nothing calls this directly
no test coverage detected
searching dependent graphs…