Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Summary
The documentation toListedColormap
states that the input should be a list or array
matplotlib/lib/matplotlib/colors.py
Lines 1175 to 1177 inb01462c
colors : list, array | |
Sequence of Matplotlib color specifications (color names or RGB(A) | |
values). |
However, when specifyingN,str
andfloat
are also supported (if one use the source code)
matplotlib/lib/matplotlib/colors.py
Lines 1199 to 1214 inb01462c
ifisinstance(colors,str): | |
self.colors= [colors]*N | |
self.monochrome=True | |
elifnp.iterable(colors): | |
iflen(colors)==1: | |
self.monochrome=True | |
self.colors=list( | |
itertools.islice(itertools.cycle(colors),N)) | |
else: | |
try: | |
gray=float(colors) | |
exceptTypeError: | |
pass | |
else: | |
self.colors= [gray]*N | |
self.monochrome=True |
This means that, e.g.,ListedColormap("#aabbcc", N=1)
works, butListedColormap("#aabbcc")
does not (there will be weird errors later, likeN=7
for the latter). Given that there ismonochrome
attribute and the documentation ofN, one may expect the latter to work as well (if the earlier works). Also,ListedColormap(["#aabbcc"])
will not set themonochrome
attribute correctly.
Proposed fix
I think there are three(?) possible solutions:
- Support scalars/strings whenN is not provided (and ideally documents that)
- Document that ifN is not None, the first argument can be a scalar or string (it is maybe easier to do
ListedColormap(0.3, N=7)
thanListedColormap([0.3]*7)
or at least require slightly less Python knowledge) - Deprecate scalar/string argument
Bonus: document thecolor
andmonochrome
attributes