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


Use the parameter color

:

import seaborn as sns
tips = sns.load_dataset("tips")
sns.boxplot(x="day", y="tip", data=tips, color="seagreen")

      



enter image description here

+4


source


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()

      

enter image description here



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")

      

enter image description here

+2


source







All Articles