将matplotlib colormap的第一种颜色设置为灰色

2024-10-02 10:26:45 发布

您现在位置:Python中文网/ 问答频道 /正文

import palettable
cmap = palettable.colorbrewer.sequential.PuRd_9.mpl_colormap
cmap(0) = (.5, .5, .5, 1.0)  # force the first color entry to be grey

*** SyntaxError: can't assign to function call

我试图将matplotlib colormap的第一种颜色设置为灰色,但是上面有错误。如何修复?在


Tags: thetoimportbemplcolorfirstcmap
1条回答
网友
1楼 · 发布于 2024-10-02 10:26:45

不安装模块选项板, 我认为错误是您用()而不是作为python语法(!)的[]为向量编制索引。 这样python就认为您在给函数调用赋值,这是没有意义的,例如:

>>cmap(0)=1
  File "<ipython-input-38-db88980f3077>", line 1
    cmap(0)=1
SyntaxError: can't assign to function call

相关问题 更多 >

    热门问题