How to generate random colors in matplotlib?

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

    Improving the answer https://stackoverflow.com/a/14720445/6654512 to work with Python3. That piece of code would sometimes generate numbers greater than 1 and matplotlib would throw an error.

    for X,Y in data:
       scatter(X, Y, c=numpy.random.random(3))
    

提交回复
热议问题