matplotlib line plot color by category code example
Example 1: change plot line color in matplotlib
plot(x, y, color='green', linestyle='dashed', marker='o',
markerfacecolor='blue', markersize=12).
Example 2: python create adictionary randomly assigning clors to categorical vairables
color_labels = df['color'].unique()
rgb_values = sns.color_palette("Set2", 8)
color_map = dict(zip(color_labels, rgb_values))
plt.scatter(df['carat'], df['price'], c=df['color'].map(color_map))
Example 3: python create adictionary randomly assigning clors to categorical vairables
sns.palplot(sns.color_palette("Set2", 8))