Reputation: 95
Im running into a confusion with categorical data plots, which is probably because I dont really understand the concept.
I have a dataframe:
A B C
0 1.438161 -0.210454 -1.983704
1 -0.283780 -0.371773 0.017580
2 0.552564 -0.610548 0.257276
3 1.931332 0.649179 -1.349062
4 1.656010 -1.373263 1.333079
5 0.944862 -0.657849 1.526811
which I can easily plot as a boxplot for each column using seaborn:
sns.boxplot(df)
However swarmplots, stripplots dont work, I guess because categorical data is needed?
value indx
1.438161 A
-0.283780 A
...
0.552564 B
1.931332 B
...
1.656010 C
0.944862 C
Is there a very easy quick way to do this, that Im not aware of?
https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.swarmplot.html
Upvotes: 3
Views: 1050
Reputation: 29711
IIUC, you can use melt
to convert one of the variables into categorical format to aid in the plotting of swarmplots
and stripplots
.
In [3]: df_sns = pd.melt(df, value_vars=['A', 'B', 'C'])
In [4]: df_sns
Out[4]:
variable value
0 A 1.438161
1 A -0.283780
2 A 0.552564
3 A 1.931332
4 A 1.656010
5 A 0.944862
6 B -0.210454
7 B -0.371773
8 B -0.610548
9 B 0.649179
10 B -1.373263
11 B -0.657849
12 C -1.983704
13 C 0.017580
14 C 0.257276
15 C -1.349062
16 C 1.333079
17 C 1.526811
In [5]: sns.swarmplot(x='variable', y='value', data=df_sns)
Out[5]: <matplotlib.axes._subplots.AxesSubplot at 0x268db2a6e10>
Upvotes: 1