user308827
user308827

Reputation: 21961

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. how to fix it?

Upvotes: 0

Views: 343

Answers (1)

Vincenzooo
Vincenzooo

Reputation: 2401

without installing the module palettetable, I think the error is that you are indexing a vector with () rather than [] as python syntax (!). This way python thinks you are assigning a value to a function call, that doesn't make sense, example:

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

Upvotes: 1

Related Questions