| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ac0ec7c commit d540ad9
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -241,7 +241,8 @@ def tick_values(self, vmin, vmax): | |||
| 241 | 241 | vmin = max(vmin, self._colorbar.norm.vmin) | |
| 242 | 242 | vmax = min(vmax, self._colorbar.norm.vmax) | |
| 243 | 243 | ticks = super().tick_values(vmin, vmax) | |
| 244 | - return ticks[(ticks >= vmin) & (ticks <= vmax)] | ||
| 244 | + rtol = (vmax - vmin) * 1e-10 | ||
| 245 | + return ticks[(ticks >= vmin - rtol) & (ticks <= vmax + rtol)] | ||
| 245 | 246 | ||
| 246 | 247 | ||
| 247 | 248 | class _ColorbarAutoMinorLocator(ticker.AutoMinorLocator): | |
@@ -297,7 +298,10 @@ def tick_values(self, vmin, vmax): | |||
| 297 | 298 | vmin = self._colorbar.norm.vmin | |
| 298 | 299 | vmax = self._colorbar.norm.vmax | |
| 299 | 300 | ticks = super().tick_values(vmin, vmax) | |
| 300 | - return ticks[(ticks >= vmin) & (ticks <= vmax)] | ||
| 301 | + rtol = (np.log10(vmax) - np.log10(vmin)) * 1e-10 | ||
| 302 | + ticks = ticks[(np.log10(ticks) >= np.log10(vmin) - rtol) & | ||
| 303 | + (np.log10(ticks) <= np.log10(vmax) + rtol)] | ||
| 304 | + return ticks | ||
| 301 | 305 | ||
| 302 | 306 | ||
| 303 | 307 | class ColorbarBase(cm.ScalarMappable): | |
@@ -406,7 +410,6 @@ def __init__(self, ax, cmap=None, | |||
| 406 | 410 | else: | |
| 407 | 411 | self.formatter = format # Assume it is a Formatter | |
| 408 | 412 | # The rest is in a method so we can recalculate when clim changes. | |
| 409 | - self.config_axis() | ||
| 410 | 413 | self.draw_all() | |
| 411 | 414 | ||
| 412 | 415 | def _extend_lower(self): | |
@@ -440,6 +443,7 @@ def draw_all(self): | |||
| 440 | 443 | # units: | |
| 441 | 444 | X, Y = self._mesh() | |
| 442 | 445 | C = self._values[:, np.newaxis] | |
| 446 | + self.config_axis() | ||
| 443 | 447 | self._config_axes(X, Y) | |
| 444 | 448 | if self.filled: | |
| 445 | 449 | self._add_solids(X, Y, C) | |
@@ -594,6 +598,7 @@ def _config_axes(self, X, Y): | |||
| 594 | 598 | ax.set_frame_on(False) | |
| 595 | 599 | ax.set_navigate(False) | |
| 596 | 600 | xy = self._outline(X, Y) | |
| 601 | + ax.ignore_existing_data_limits = True | ||
| 597 | 602 | ax.update_datalim(xy) | |
| 598 | 603 | ax.set_xlim(*ax.dataLim.intervalx) | |
| 599 | 604 | ax.set_ylim(*ax.dataLim.intervaly) | |
@@ -1151,7 +1156,6 @@ def update_bruteforce(self, mappable): | |||
| 1151 | 1156 | self.set_alpha(mappable.get_alpha()) | |
| 1152 | 1157 | self.cmap = mappable.cmap | |
| 1153 | 1158 | self.norm = mappable.norm | |
| 1154 | - self.config_axis() | ||
| 1155 | 1159 | self.draw_all() | |
| 1156 | 1160 | if isinstance(self.mappable, contour.ContourSet): | |
| 1157 | 1161 | CS = self.mappable | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ | |||
| 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 | ||
| 10 | 11 | ||
| 11 | 12 | ||
| 12 | 13 | def _get_cmap_norms(): | |
@@ -411,3 +412,27 @@ def test_colorbar_log_minortick_labels(): | |||
| 411 | 412 | r'$\mathdefault{4\times10^{4}}$'] | |
| 412 | 413 | for l, exp in zip(lb, expected): | |
| 413 | 414 | 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) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments