Matplotlib Plot Lines with Colors Through Colormap

前端 未结 4 2120
眼角桃花
眼角桃花 2020-12-01 03:11

I am plotting multiple lines on a single plot and I want them to run through the spectrum of a colormap, not just the same 6 or 7 colors. The code is akin to this:



        
4条回答
  •  [愿得一人]
    2020-12-01 03:23

    If you are using continuous color pallets like brg, hsv, jet or the default one then you can do like this:

    color = plt.cm.hsv(r) # r is 0 to 1 inclusive
    

    Now you can pass this color value to any API you want like this:

    line = matplotlib.lines.Line2D(xdata, ydata, color=color)
    

提交回复
热议问题