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

Function test_colorbar_format

lib/matplotlib/tests/test_colorbar.py:627–650  ·  view source on GitHub ↗
(fmt)

Source from the content-addressed store, hash-verified

625
626@pytest.mark.parametrize('fmt', ['%4.2e', '{x:.2e}'])
627def 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
653def test_colorbar_scale_reset():

Callers

nothing calls this directly

Calls 8

imshowMethod · 0.80
get_ticklabelsMethod · 0.80
subplotsMethod · 0.45
colorbarMethod · 0.45
drawMethod · 0.45
get_textMethod · 0.45
set_climMethod · 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…