|
7 | 7 | from matplotlib.colors import BoundaryNorm, LogNorm, PowerNorm |
8 | 8 | from matplotlib.cm import get_cmap |
9 | 9 | from matplotlib.colorbar import ColorbarBase |
| 10 | +from matplotlib.ticker import LogLocator, LogFormatter |
| 11 | + |
10 | 12 |
|
11 | 13 |
|
12 | 14 | def _get_cmap_norms(): |
@@ -396,3 +398,28 @@ def test_colorbar_axes_kw(): |
396 | 398 | plt.imshow(([[1, 2], [3, 4]])) |
397 | 399 | plt.colorbar(orientation='horizontal', fraction=0.2, pad=0.2, shrink=0.5, |
398 | 400 | 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