statsmodels mosaic plot - how to order categories
<p>Here is dataframe:</p>

<pre><code>import pandas as pd
from statsmodels.graphics.mosaicplot import mosaic

df = pd.DataFrame({'size' : ['small', 'large', 'large', 'small', 'large', 'small'],
'length' : ['long', 'short', 'short', 'long', 'long', 'short']})
</code></pre>

<p>if I plot it <code>mosaic(df, ['size', 'length'])</code> it will display <code>size</code> in this order <code>small</code> then <code>large</code>, while I would like to have <code>large</code> and then <code>small</code>. Is there way to achieve it?</p>

<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_values.html" rel="nofollow"><code>sort_values</code></a> to sort values present in the size column to alter the order.</p>

<pre><code>mosaic(df.sort_values('size'), ['size', 'length'])
</code></pre>

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

python pandas statsmodels mosaic