Closed
Description
Bug report
Bug summary
LinearSegmentedColormap
with N=1
gives confusing error message.
Code for reproduction
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import colors
plt.figure()
fig = plt.gcf()
ax = plt.gca()
x = np.arange(0,3,1)
y = np.arange(0,3,1)
X, Y = np.meshgrid(x, y)
Z = Y
cs = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
N = 1 # No error if this is changed to 2
cmapg = colors.LinearSegmentedColormap.from_list('a',cs,N)
ax.pcolormesh(X, Y, Z, cmap=cmapg)
fig.show()
Actual outcome
In Matplotlib 3.1rc1, error is
File "/Users/abc/anaconda3/envs/python3.6/lib/python3.6/site-packages/matplotlib-3.1.0rc1-py3.6-macosx-10.7-x86_64.egg/matplotlib/colors.py", line 663, in _init
self.N, self._segmentdata['red'], self._gamma)
ValueError: could not broadcast input array from shape (2) into shape (1)
Expected outcome
I ran into this error because I was plotting a matrix with values of NaN or 1 and only needed to specify a single color (there is probably a better way to do this). This worked in Matplotlib 2.2.2 as desired but caused a confusing error message in Matplotlib 3.1rc1.
I expected this to either work as-is or for pcolormap
throw an error indicating that the passed colormap is invalid.
Matplotlib version
- Operating system: OS-X 10.14
- Matplotlib version: 3.1rc1
- Matplotlib backend (
print(matplotlib.get_backend())
): Qt5Agg - Python version: 3.6
- Jupyter version (if applicable):
- Other libraries: Using Matplotlib installed with
conda create -n python3.6 python=3.6
Metadata
Metadata
Assignees
Labels
No labels