Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 294ff2d

Browse files
committed
TST: add test for re-normalizing image
1 parent 4293b58 commit 294ff2d

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

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():
@@ -396,3 +398,28 @@ def test_colorbar_axes_kw():
396398
plt.imshow(([[1, 2], [3, 4]]))
397399
plt.colorbar(orientation='horizontal', fraction=0.2, pad=0.2, shrink=0.5,
398400
aspect=10, anchor=(0., 0.), panchor=(0., 1.))
401+
402+
403+
def test_colorbar_renorm():
404+
x,y = np.ogrid[-4:4:31j,-4:4:31j]
405+
z = 120000*np.exp(-x**2-y**2)
406+
407+
fig, ax = plt.subplots()
408+
409+
im = ax.imshow(z)
410+
cbar = fig.colorbar(im)
411+
412+
norm = LogNorm(z.min(), z.max())
413+
im.set_norm(norm)
414+
cbar.set_norm(norm)
415+
cbar.locator = LogLocator()
416+
cbar.formatter = LogFormatter()
417+
cbar.update_normal(im)
418+
assert np.isclose(cbar.vmin, z.min())
419+
420+
norm = LogNorm(z.min() * 1000, z.max() * 1000)
421+
im.set_norm(norm)
422+
cbar.set_norm(norm)
423+
cbar.update_normal(im)
424+
assert np.isclose(cbar.vmin, z.min() * 1000)
425+
assert np.isclose(cbar.vmax, z.max() * 1000)

0 commit comments

Comments
 (0)