The Python Oracle

Seaborn Violinplot change order of hue

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 3

--

Chapters
00:00 Question
00:53 Accepted answer (Score 9)
01:13 Thank you

--

Full question
https://stackoverflow.com/questions/5937...

Question links:
[image]: https://i.stack.imgur.com/xtxI4.png

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #pandas #seaborn

#avk47



ACCEPTED ANSWER

Score 10


You need to set hue_order:

import pandas as pd
import seaborn as sns
import numpy as np

df = pd.DataFrame({'my_bool': pd.Series(np.random.choice([True,False],20),dtype='bool'),
                'value': pd.Series(np.random.choice(200,20),dtype='int'),
                'my_group': np.random.choice(['A','B'],20)})
sns.violinplot(x='my_group',data=df,y='value',hue='my_bool', hue_order= [True, False], split=True, palette = {True:'blue', False:'red'})