Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

python - Boxplot: colors by x value and hues differentiated by pattern

Say I have a boxplot like the one shown below:

example

I would like to achieve a different coloring:

  • Fri, Sat and Sun would be colored blue; Thur would be colored red

  • I would like to differentiate hues with a pattern in the box (stripped or something)

I can't find a way to do this manipulation using seaborn palette.

I know I can mess with the boxes of a boxplot in matplotlib directly but seaborn gives me the axes back. How can I get the boxes in this case?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The boxes end up in the artists list on the returned axes, so you just need to manipulate the attributes on those objects:

ax = sns.boxplot(data=x)
box = ax.artists[0]
box. set_facecolor("white")

etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...