Closed

Description
Bug report
Bug summary
import matplotlib as mpl
import matplotlib.pyplot as plt
cmap = plt.cm.jet
bounds = [0, 1]
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
norm(0.5)
Gives:
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-160-8a8135eaeb3c> in <module>
2 bounds = [0, 1]
3 norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
----> 4 norm(0.5)
/usr/local/lib/python3.6/dist-packages/matplotlib/colors.py in __call__(self, value, clip)
1442 iret[xx >= b] = i
1443 if self._interp:
-> 1444 scalefac = (self.Ncmap - 1) / (self.N - 2)
1445 iret = (iret * scalefac).astype(np.int16)
1446 iret[xx < self.vmin] = -1
ZeroDivisionError: division by zero
Expected outcome
not an error: just an integer.
Matplotlib version
mpl.__version__: 3.2.1
os.name: posix
mpl.get_backend(): module://ipykernel.pylab.backend_inline
sys.version: 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0]
$ jupyter --version
jupyter core : 4.6.3
jupyter-notebook : 6.0.3
qtconsole : 4.7.1
ipython : 7.13.0
ipykernel : 5.1.1
jupyter client : 6.0.0
jupyter lab : 1.2.14
nbconvert : 5.6.1
ipywidgets : 7.5.1
nbformat : 4.4.0
traitlets : 4.3.3