How to generate random colors in Matplotlib in Python

Generating random colors for Matplotlib involves generating random RGB values, which are the 3-number encodings for colors.

Solution for How to generate random colors in Matplotlib in Python : You can use numpy.random.rand() to generate random colors Call numpy.random.rand(num_colors, 3) to get a number of random RGB color values equal to num_colors. Pass the result of this function to the keyword argument c of any matplotlib plotting function, like pyplot.scatter(x, y, c=colors).


how-to-generate-random-colors-in-matplotlib-in-python