I would like to customize different linecolors for diffferent box in seaborn.boxplot, here is a toy example:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.pyplot import figure
figure(figsize=(8, 6), dpi=80)
PROPS = {
'boxprops':{'facecolor':'none', 'edgecolor':'red'},
'medianprops':{'color':'green'},
'whiskerprops':{'color':'blue'},
'capprops':{'color':'yellow'}
}
df_dict={'court':[1,1,2,2,3,3,4,4],
'player':['Bob','Ian','Bob','Ian','Bob','Ian','Ian','Bob'],
'score':[6,8,12,15,8,16,11,13],
'win':['no','yes','no','yes','no','yes','no','yes']}
df=pd.DataFrame.from_dict(df_dict)
ax = sns.boxplot(y='score',x='player',data=df,**PROPS)
ax = sns.swarmplot(y='score',x='player',hue='win',data=df,s=5,palette=['red','green'])
sns.lineplot(
data=df, y="score", x="player", units="court",
color="#bdbdbd", estimator=None
)
plt.show()
Here, the parameter 'PROPS' works for each box. How can I set different 'boxprops', 'medianprops', 'whiskerprops' and 'capprops' for the two boxes seperately?
I have found a similar question in assign a color to a specific box in seaborn.boxplot. However, this question is too old and the answers not worked for me.