The Python Oracle

Seaborn, violin plot with one data per column

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Magical Minnie Puzzles

--

Chapters
00:00 Seaborn, Violin Plot With One Data Per Column
00:50 Answer 1 Score 1
01:10 Accepted Answer Score 32
01:25 Thank you

--

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

--

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.