0

My data format is like this:

+--------+----------+----------+----------+----------+----------+----------+
| method | Feature1 | Feature2 | Feature3 | Feature4 | Feature5 | Feature6 |
+--------+----------+----------+----------+----------+----------+----------+
| A      | value    | value    | value    | value    | value    | value    |
+--------+----------+----------+----------+----------+----------+----------+
| B      | value    | value    | value    | value    | value    | value    |
+--------+----------+----------+----------+----------+----------+----------+
| A      | value    | value    | value    | value    | value    | value    |
+--------+----------+----------+----------+----------+----------+----------+

I want to plot violinplot like this:

enter image description here

Where the X-axis is the features and Y-axis is the whole column value, and hue to method. So how to plot with seaborn? I do read the example code, which seems like I have to reconstruct my data?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Ranglage
  • 9
  • 3

1 Answers1

0

I cannot test without the data, but this should work.

First, transform your data to tidy form

df = df.melt(id_vars=['method'])
# method | variable | value
#   A    | Feature1 |  ...  
#   A    | Feature2 |  ...   

Then, use the standard seaborn API

sns.violinplot(x='variable', y='value', hue='method', data=df)
phi
  • 10,572
  • 3
  • 21
  • 30