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

Skip to content

Commit 497ffa8

Browse files
committed
Merge pull request #5700 from efiring/colorbar_tick_trim
BUG: handle colorbar ticks with boundaries and NoNorm; closes #5673
2 parents 81b8ced + 1616f67 commit 497ffa8

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

lib/matplotlib/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ def _ticker(self):
580580
else:
581581
b = self._boundaries[self._inside]
582582
locator = ticker.FixedLocator(b, nbins=10)
583-
if isinstance(self.norm, colors.NoNorm):
583+
if isinstance(self.norm, colors.NoNorm) and self.boundaries is None:
584584
intv = self._values[0], self._values[-1]
585585
else:
586586
intv = self.vmin, self.vmax

lib/matplotlib/tests/test_colorbar.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,22 @@ def test_colorbar_closed_patch():
282282
extend='neither', values=values)
283283

284284

285+
@cleanup
286+
def test_colorbar_ticks():
287+
# test fix for #5673
288+
fig, ax = plt.subplots()
289+
x = np.arange(-3.0, 4.001)
290+
y = np.arange(-4.0, 3.001)
291+
X, Y = np.meshgrid(x, y)
292+
Z = X * Y
293+
clevs = np.array([-12, -5, 0, 5, 12], dtype=float)
294+
colors = ['r', 'g', 'b', 'c']
295+
cs = ax.contourf(X, Y, Z, clevs, colors=colors)
296+
cbar = fig.colorbar(cs, ax=ax, extend='neither',
297+
orientation='horizontal', ticks=clevs)
298+
assert len(cbar.ax.xaxis.get_ticklocs()) == len(clevs)
299+
300+
285301
if __name__ == '__main__':
286302
import nose
287303
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)