The Python Oracle

Seaborn, violin plot with one data per column

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 Looping

--

Chapters
00:00 Question
01:15 Accepted answer (Score 32)
01:42 Answer 2 (Score 1)
02:13 Thank you

--

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

Question links:
http://seaborn.pydata.org/generated/seab...
http://seaborn.pydata.org/examples/elabo...

Accepted answer links:
[image]: https://i.stack.imgur.com/IXNT9.png

Answer 2 links:
[example]: http://chrisalbon.com/python/pandas_with...
[image]: https://i.stack.imgur.com/jOPGZ.png

--

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

--

Tags
#python #seaborn

#avk47



ACCEPTED ANSWER

Score 32


If understand your question correctly, you need to reshape your dataframe to have it in long format:

df = pd.melt(df, value_vars=['A', 'B'], id_vars='Success')
sns.violinplot(x='variable', y='value', hue='Success', data=df)
plt.show()

enter image description here




ANSWER 2

Score 1


I was able to adapt an example of a violin plot over a DataFrame like so:

df = pd.DataFrame({"Success": 50 * ["Yes"] + 50 * ["No"], 
                   "A": np.random.randint(1, 7, 100), 
                   "B": np.random.randint(1, 7, 100)})
sns.violinplot(df.A, df.B, df.Success, inner="quartile", split=True)
sns.plt.show()

Seaborn violin graph over Pandas DataFrame

Clearly, it still needs some work: the A scale should be sized to fit a single half-violin, for example.