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

# 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 3: python create adictionary randomly assigning clors to categorical vairables

sns.palplot(sns.color_palette("Set2", 8))