matplotlib / matplotlib/cmocean
`cmocean.tools.print_colormaps` snippet in the docs raises an error
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 269
- Forks
- 54
- PR merge metrics
- No merged PRs in 30d
Description
Hello! I love your work, this is my favorite set of colormaps.
Today I wanted to run some code from [the docs](https://matplotlib.org/cmocean/#capabilities):
```python
import cmocean
cmaps = cmocean.cm.cmap_d
cmocean.tools.print_colormaps(cmaps)
```
and it produces the following exception and traceback:
```
Traceback (most recent call last):
File "/home/mfisher/Projects/_test/extend-colormaps-js/test.py", line 4, in
cmocean.tools.print_colormaps(cmaps)
File "/home/mfisher/Projects/_test/extend-colormaps-js/.pixi/envs/default/lib/python3.12/site-packages/cmocean/tools.py", line 25, in print_colormaps
rgbtemp = cmap(np.linspace(0, 1, N))[np.newaxis, :, :3][0]
^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'str' object is not callable
```
The issue appears to be here:
https://github.com/matplotlib/cmocean/blob/59c35002c3aa5296b65d9646e52604c627441eb6/cmocean/tools.py#L23
We loop over the `cmaps` object, which is a dictionary of colormap name keys to colormap object values in this invocation, but the function expects the object to be a list of colormap objects.
So the docs could be updated to:
```python
import cmocean
cmaps = cmocean.cm.cmap_d
cmocean.tools.print_colormaps(cmaps.values())
```
But after running this code I don't see the output files!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the capabilities example linked in the issue and cmocean/tools.py around line 23; run the documented snippet and inspect how print_colormaps handles its input and writes output. Update the documentation example so it no longer raises the reported error, and clarify or verify where its output files should appear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100