How to generate random colors in matplotlib?

前端 未结 11 2224
长情又很酷
长情又很酷 2020-12-12 16:13

What\'s the trivial example of how to generate random colors for passing to plotting functions?

I\'m calling scatter inside a loop and want each plot a different col

11条回答
  •  借酒劲吻你
    2020-12-12 16:43

    enter code here
    
    import numpy as np
    
    clrs = np.linspace( 0, 1, 18 )  # It will generate 
    # color only for 18 for more change the number
    np.random.shuffle(clrs)
    colors = []
    for i in range(0, 72, 4):
        idx = np.arange( 0, 18, 1 )
        np.random.shuffle(idx)
        r = clrs[idx[0]]
        g = clrs[idx[1]]
        b = clrs[idx[2]]
        a = clrs[idx[3]]
        colors.append([r, g, b, a])
    

提交回复
热议问题