Seaborn boxplot + swarmplot: different color for x, different symbol for shades

I am trying to create a box using a sea tree with other groups xand an extra one hues. See this code:

tips = sns.load_dataset("tips")

sns.stripplot(x="day", y="total_bill", hue="smoker",
              data=tips, jitter=True,
              palette="Set2", split=True,linewidth=1,edgecolor='gray')

sns.boxplot(x="day", y="total_bill", hue="smoker",
            data=tips,palette="Set2",fliersize=0)

enter image description here

I would like each xboxplots (in this example, every day) to have a different color, while each hue(in this case, smoker / non-smoker) is represented with a different symbol on swarmplot.

I tried to play with an argument palette, but did not get what I wanted. I also tried playing with artistsdirectly, but changing facecolorboxplot also changes for some reason edgecolor, and I don't know how to change characters anyway to swarmplot.

+4
1

: edgecolor, facecolor .

ax = sns.boxplot(x="day", y="total_bill", hue="smoker",
            data=tips,fliersize=0)

colors = sns.color_palette('husl',n_colors=4)
colors = sp.repeat(colors,2,axis=0)

for artist,color in zip(ax.artists,colors):
    artist.set_facecolor(color)
    artist.set_edgecolor(color)

: , . [pc for pc in ax.get_children() if type(pc) == PathCollection], ..

0

Source: https://habr.com/ru/post/1661462/


All Articles