assign colours to categories python code example
Example 1: python create adictionary randomly assigning clors to categorical vairables
# Unique category labels: 'D', 'F', 'G', ...
color_labels = df['color'].unique()
# List of RGB triplets
rgb_values = sns.color_palette("Set2", 8)
# Map label to RGB
color_map = dict(zip(color_labels, rgb_values))
# Finally use the mapped values
plt.scatter(df['carat'], df['price'], c=df['color'].map(color_map))
Example 2: python create adictionary randomly assigning clors to categorical vairables
sns.palplot(sns.color_palette("Set2", 8))