I am trying to generate N random colors P times. For example I have 10 different plots with 20 bars in each and I wan to assign each bar a different color. How can I generate 20 random colors for each bar for 10 times?
I have written this code but it is showing me errors.
def generate_n_random_cmap(how_many=20,list_len=10):
'''
Generate list of 20 colors 10 times by default.
NOTE: Colors can be duplicated if lit_len is greater than length of plt.colormap()
'''
import random
import matplotlib.pyplot as plt
c_list = []
while len(c_list)!=list_len:
try:
c_list.append(plt.cm.get_cmap(random.choice(plt.colormaps()),how_many).colors)
except :
None
return random.shuffle(c_list)
And the Error I get is:
'LinearSegmentedColormap' object has no attribute 'colors'
Is there any other method? Colors should be random in nature.