Skip to content

Commit 3add532

Browse files
committed
TST: add test for re-normalizing image
1 parent 777c9e5 commit 3add532

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/matplotlib/tests/test_colorbar.py

+25
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from matplotlib.colors import BoundaryNorm, LogNorm, PowerNorm
88
from matplotlib.cm import get_cmap
99
from matplotlib.colorbar import ColorbarBase
10+
from matplotlib.ticker import LogLocator, LogFormatter
1011

1112

1213
def _get_cmap_norms():
@@ -411,3 +412,27 @@ def test_colorbar_log_minortick_labels():
411412
r'$\mathdefault{4\times10^{4}}$']
412413
for l, exp in zip(lb, expected):
413414
assert l.get_text() == exp
415+
416+
417+
def test_colorbar_renorm():
418+
x, y = np.ogrid[-4:4:31j, -4:4:31j]
419+
z = 120000*np.exp(-x**2 - y**2)
420+
421+
fig, ax = plt.subplots()
422+
im = ax.imshow(z)
423+
cbar = fig.colorbar(im)
424+
425+
norm = LogNorm(z.min(), z.max())
426+
im.set_norm(norm)
427+
cbar.set_norm(norm)
428+
cbar.locator = LogLocator()
429+
cbar.formatter = LogFormatter()
430+
cbar.update_normal(im)
431+
assert np.isclose(cbar.vmin, z.min())
432+
433+
norm = LogNorm(z.min() * 1000, z.max() * 1000)
434+
im.set_norm(norm)
435+
cbar.set_norm(norm)
436+
cbar.update_normal(im)
437+
assert np.isclose(cbar.vmin, z.min() * 1000)
438+
assert np.isclose(cbar.vmax, z.max() * 1000)

0 commit comments

Comments
 (0)