Create a color generator from given colormap in matplotlib

前端 未结 1 1614
鱼传尺愫
鱼传尺愫 2021-01-30 15:03

I have a series of lines that each need to be plotted with a separate colour. Each line is actually made up of several data sets (positive, negative regions etc.) and so I\'d li

相关标签:
1条回答
  • 2021-01-30 15:11

    To index colors from a specific colormap you can use:

    import pylab
    NUM_COLORS = 22
    
    cm = pylab.get_cmap('gist_rainbow')
    for i in range(NUM_COLORS):
        color = cm(1.*i/NUM_COLORS)  # color will now be an RGBA tuple
    
    # or if you really want a generator:
    cgen = (cm(1.*i/NUM_COLORS) for i in range(NUM_COLORS))
    
    0 讨论(0)
提交回复
热议问题