4

Here is dataframe:

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']})

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

user1700890
  • 7,144
  • 18
  • 87
  • 183

1 Answers1

4

Use sort_values to sort values present in the size column to alter the order.

mosaic(df.sort_values('size'), ['size', 'length'])

Image

Nickil Maveli
  • 29,155
  • 8
  • 82
  • 85