Answer a question

I’d like to employ the reverse Spectral colormap ,

https://matplotlib.org/examples/color/colormaps_reference.html

for a lineplot.

This works fine with a hex bin plot::

color_map = plt.cm.Spectral_r
image = plt.hexbin(x,y,cmap=color_map)

but when I do

ax1.plot(x,y, cmp=color_map)

this gives me::

AttributeError: Unknown property cmap

Note, I just want to set the colormap and let matplotliob do the rest; i.e. I don't want to have a color=' argument in the .plot command.

Answers

You can have a look at this solution - the third variant is what you want:

https://stackoverflow.com/a/57227821/5972778

You need to know how many lines you're plotting in advance, as otherwise it doesn't know how to choose the colours from the range.

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐