matplotlib / matplotlib/cmocean

`cmocean.tools.print_colormaps` snippet in the docs raises an error

未关闭
#118 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
269
派生
54
PR 合并指标
30 天内没有已合并 PR

描述

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!

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 issue 中链接的 capabilities 示例以及第 23 行附近的 cmocean/tools.py 开始;运行文档中的代码片段,并检查 print_colormaps 如何处理输入以及写入输出。更新文档示例,使其不再引发所报告的错误,并明确或验证其输出文件应出现在哪里。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
documentation
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
基本清楚
新手友好度
52/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。