Reputation: 13660
I am using seaborn and want to generate a box plot where all boxes have the same color. For some reason seaborn uses different colors for each box and doesn't have an option to stop this behavior and set the same color for all boxes.
How can I force seaborn to use the same color for all boxes?
fig, ax = plt.subplots(figsize=(10, 20))
sns.boxplot(y='categorical_var', x='numeric_var', ax=ax)
Upvotes: 7
Views: 10034
Reputation: 48992
Use the color
parameter:
import seaborn as sns
tips = sns.load_dataset("tips")
sns.boxplot(x="day", y="tip", data=tips, color="seagreen")
Upvotes: 13
Reputation: 36635
Make your own palette and set the color of boxes like:
import seaborn as sns
import matplotlib.pylab as plt
sns.set_color_codes()
tips = sns.load_dataset("tips")
pal = {day: "b" for day in tips.day.unique()}
sns.boxplot(x="day", y="total_bill", data=tips, palette=pal)
plt.show()
Another way is to iterate over artists of boxplot and set the color with set_facecolor
for every artist of axis istance:
ax = sns.boxplot(x="day", y="total_bill", data=tips)
for box in ax.artists:
box.set_facecolor("green")
Upvotes: 2