Seaborn categorical plot with hue from DataFrame rows
<p>I have this pandas DataFrame:</p>

<pre><code>&gt;&gt;&gt; print(df)
Channel     0     1     2     3     4     5     6     7
Sample                                                 
7d       3.82  4.10  3.86  3.86  3.95  3.65  3.43  3.63
12d      2.97  4.32  3.50  3.58  3.22  3.37  3.58  3.78
17d      4.01  4.04  4.10  3.43  3.76  3.26  3.35  3.48
DO       3.07  3.58  3.14  3.22  3.11  3.09  3.16  3.16
</code></pre>

<p>I want to do a plot similar to this (the code is <code>sns.swarmplot(df)</code>):</p>

<p><a href="https://i.stack.imgur.com/YeUvO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YeUvO.png" alt="enter image description here"></a></p>

<p>But the colors should be set not per-channel (i.e. DataFrame column) but per-sample (i.e. DataFrame rows). So each "category" on the x-axis will have 4 colors corresponding to the rows 7d, 12d, 17d and DO.</p>

<p>Is there an easy way to accomplish this in seaborn?</p>

<p><strong>EDIT</strong>: I should add that I tried using the <code>hue</code> keyword, but it says it requires using also <code>x</code> and <code>y</code> keyword. According to <a href="https://web.stanford.edu/~mwaskom/software/seaborn/generated/seaborn.swarmplot.html?highlight=swarmplot#seaborn.swarmplot" rel="nofollow noreferrer">this example</a> seems that I need to create a new DataFrame with all numeric values in one column and two other columns with sample and channel information. Then I can call the plot as <code>sns.swarmplot(x='Channel', y='values', hue='Sample')</code>. Is there a more direct way that does not involve creating an additional ad-hoc DataFrame?</p>

<p><strong>EDIT2</strong>: Following @BrenBarn suggestion, I end up creating a new "tidy" DataFrame with:</p>

<pre><code>dd = []
for sa in df.index:
    print(sa)
    d = pd.DataFrame(df.loc[sa]).reset_index()
    d.columns = ['Channel', 'Leakage']
    d['Sample'] = sa
    dd.append(d)
ddf = pd.concat(dd)
</code></pre>

<p>And then plotting the data with:</p>

<pre><code>sns.swarmplot(x='Channel', y='Leakage', hue='Sample', data=ddf)
</code></pre>

<p>which gives the plot I expected:</p>

<p><a href="https://i.stack.imgur.com/L8E8I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L8E8I.png" alt="enter image description here"></a></p>

<p>I was hoping there was a way to
tell seaborn to use original "2-D table" format to do the plot
which is much more compact and natural for this kind of data. 
If this is possible I would accept the answer ;).</p>