Generate random colors (RGB)
You could also use Hex Color Code,
Name Hex Color Code RGB Color CodeRed #FF0000 rgb(255, 0, 0)Maroon #800000 rgb(128, 0, 0)Yellow #FFFF00 rgb(255, 255, 0)Olive #808000 rgb(128, 128, 0)
For example
import matplotlib.pyplot as pltimport randomnumber_of_colors = 8color = ["#"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]) for i in range(number_of_colors)]print(color)
['#C7980A', '#F4651F', '#82D8A7', '#CC3A05', '#575E76', '#156943', '#0BD055', '#ACD338']
Lets try plotting them in a scatter plot
for i in range(number_of_colors): plt.scatter(random.randint(0, 10), random.randint(0,10), c=color[i], s=200)plt.show()
Here:
def random_color(): rgbl=[255,0,0] random.shuffle(rgbl) return tuple(rgbl)
The result is either red, green or blue. The method is not applicable to other sets of colors though, where you'd have to build a list of all the colors you want to choose from and then use random.choice to pick one at random.