How to generate random colors in matplotlib?

前端 未结 11 2240
长情又很酷
长情又很酷 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:26

    Here is a more concise version of Ali's answer giving one distinct color per plot :

    import matplotlib.pyplot as plt
    
    N = len(data)
    cmap = plt.cm.get_cmap("hsv", N+1)
    for i in range(N):
        X,Y = data[i]
        plt.scatter(X, Y, c=cmap(i))
    

提交回复
热议问题