简体   繁体   English

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

[英]set the first color of a matplotlib colormap to gray

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

I am trying to set the first color of a matplotlib colormap to gray, but getting error above. 我正在尝试将matplotlib颜色图的第一种颜色设置为灰色,但是上面出现错误。 how to fix it? 如何解决?

without installing the module palettetable, I think the error is that you are indexing a vector with () rather than [] as python syntax (!). 没有安装模块调色板表,我认为错误是您正在使用()而不是[]作为python语法(!)来索引向量。 This way python thinks you are assigning a value to a function call, that doesn't make sense, example: python以此方式认为您正在为函数调用分配一个值,这没有意义,例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM