(fmt)
| 625 | |
| 626 | @pytest.mark.parametrize('fmt', ['%4.2e', '{x:.2e}']) |
| 627 | def test_colorbar_format(fmt): |
| 628 | # make sure that format is passed properly |
| 629 | x, y = np.ogrid[-4:4:31j, -4:4:31j] |
| 630 | z = 120000*np.exp(-x**2 - y**2) |
| 631 | |
| 632 | fig, ax = plt.subplots() |
| 633 | im = ax.imshow(z) |
| 634 | cbar = fig.colorbar(im, format=fmt) |
| 635 | fig.canvas.draw() |
| 636 | assert cbar.ax.yaxis.get_ticklabels()[4].get_text() == '8.00e+04' |
| 637 | |
| 638 | # make sure that if we change the clim of the mappable that the |
| 639 | # formatting is *not* lost: |
| 640 | im.set_clim([4, 200]) |
| 641 | fig.canvas.draw() |
| 642 | assert cbar.ax.yaxis.get_ticklabels()[4].get_text() == '2.00e+02' |
| 643 | |
| 644 | # but if we change the norm: |
| 645 | # when we require numpy >= 2, vmin can be 0.1, but at numpy 1.x this is |
| 646 | # sensitive to floating point errors |
| 647 | im.set_norm(LogNorm(vmin=0.09999, vmax=10)) |
| 648 | fig.canvas.draw() |
| 649 | assert (cbar.ax.yaxis.get_ticklabels()[0].get_text() == |
| 650 | '$\\mathdefault{10^{-2}}$') |
| 651 | |
| 652 | |
| 653 | def test_colorbar_scale_reset(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…