8000 TST: add test for re-normalizing image · matplotlib/matplotlib@70c50d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 70c50d1

Browse files
committed
TST: add test for re-normalizing image
1 parent a2d22f2 commit 70c50d1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lib/matplotlib/tests/test_colorbar.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
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
11+
1012

1113

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

0 commit comments

Comments
 (0)
0