python
config_error
ai_generated
true
ValueError: 'viridis' is not a valid colormap name. Valid names are: ['Accent', 'Accent_r', 'Blues', ...]
ID: python/matplotlib-cmap-name-error
80%Fix Rate
83%Confidence
0Evidence
2024-06-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
Root Cause
Using a typo in colormap name (e.g., 'viridis' instead of 'viridis'? Actually 'viridis' is correct; if user types 'viridiss' or 'virid' it fails). The error occurs when the string does not match any registered colormap.
generic中文
颜色映射名称拼写错误(例如'viridis'拼写为'viridiss')或使用了不存在的名称,导致无法找到匹配的颜色映射。
Workarounds
-
95% success Use the correct spelling from the list of valid colormaps
plt.imshow(data, cmap='viridis')
-
90% success List all available colormaps to find the correct one
from matplotlib import cm; print([m for m in cm._cmap_registry.keys()])
Dead Ends
Common approaches that don't work:
-
Assuming case insensitivity and trying 'Viridis'
80% fail
Colormap names are case-sensitive; 'Viridis' is not valid, only 'viridis' works.
-
Using a numeric index like 0 for the first colormap
90% fail
Colormaps are accessed by name, not numeric index.