Reputation: 281
I'm using seaborn to create a horizontal bar chart. From this example, here is how I am setting colors.
sns.set_color_codes("pastel")
sns.barplot(x="total", y="abbrev", data=crashes, label="Total", color="b")
So in this example the field 'total' will have the color "b" (for blue) from the "pastel" palette.
I have around 60 different fields, and I do not want to set all the colors manually. Is there a way to let seaborn choose the colors (and even the palette) automatically?
As it stands my plan is to create the barplots in a cycle
for field in fields:
sns.set_color_codes(foo)
sns.barplot(x=field, y="abbrev", data=crashes, label=field, color="bar")
where foo
and bar
are somehow generated for me by seaborn.
Upvotes: 1
Views: 2905
Reputation: 4044
You can use the argument palette=
in the barplot method as specified in documentation Seaborn Barplot.
A really good example of values that you can provide to palette
method is available at Seaborn Color Palette
my_palette = sns.color_palette("muted")
sns.barplot(x=field, y="abbrev", data=crashes, label=field, palette=my_palette)
Upvotes: 5