pandas plot with different variable for subplots and colour?
<p>Currently this code:</p>

<pre><code>count_df = (df[['rank', 'name', 'variable', 'value']]
    .groupby(['rank', 'variable', 'name'])
    .agg('count')
    .unstack())
count_df .head()
#               value                          
# name           1lin STH_km27_lin ST_lin S_lin
# rank variable                                
# 1.0  NEE         24          115     33    28
#      Qg          23           54     14     9
#      Qh          37          124     11    28
# ...
count_df.plot(kind='bar')
</code></pre>

<p>gets me this plot:</p>

<p><a href="http://i.stack.imgur.com/1bxB6.png" rel="nofollow"><img src="http://i.stack.imgur.com/1bxB6.png" alt="bar plot with too much shit on it"></a></p>

<p>using <code>subplots=True</code> in the <code>.plot()</code> call gets me this:</p>

<p><a href="http://i.stack.imgur.com/aaAxN.png" rel="nofollow"><img src="http://i.stack.imgur.com/aaAxN.png" alt="useless subplots"></a></p>

<p>which is pretty useless, because the colours are mapped to the same variable as the subplot facetting. Is there a way to choose which column/index is used for the sub-plotting, so that I can still have colours per <code>name</code> (<code>count_df</code> column header), but sub-plots per <code>variable</code>, so that each subplot has a bar per <code>name/rank</code>, grouped by <code>rank</code>, and coloured by <code>name</code>? </p>

<p>Hrm. I suspect this isn't doable in pandas by itself, but I found a way to do it in Seaborn:</p>

<pre><code>import seaborn as sns

cdf = (df[['rank', 'name', 'variable', 'value']]
           .groupby(['rank', 'variable', 'name'])
           .agg('count'))
sns.factorplot(x="rank", y="value", row="variable", hue="name",
               data=cdf.reset_index(), kind='bar')
</code></pre>

<p>which results in:</p>

<p><a href="http://i.stack.imgur.com/PKfZu.png" rel="nofollow"><img src="http://i.stack.imgur.com/PKfZu.png" alt="barplot by rank, variable, and name"></a></p>

<p>which is close enough for my purposes</p>

python pandas matplotlib plot