Seaborn Boxplot with the same color for all boxes
I am using a sea vessel and want to create a box where all the boxes are the same color. For some reason, the naval vessel uses different colors for each box and has no way to stop this behavior and set the same color for all boxes.
How can I force the marine vessel 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)
+3
source to share
2 answers
Create your own palette and set the color of fields such as:
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 the boxplot artists and set the color s set_facecolor
for each axis artist:
ax = sns.boxplot(x="day", y="total_bill", data=tips)
for box in ax.artists:
box.set_facecolor("green")
+2
source to share