Skip to content

cmocean.tools.print_colormaps snippet in the docs raises an error #118

@mfisher87

Description

@mfisher87

Hello! I love your work, this is my favorite set of colormaps.

Today I wanted to run some code from the docs:

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 <module>
    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:

for cmap in cmaps:

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:

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions