I have collected the frequencies in which combinations of certain categorical parameters occur in a DataFrame. Applying a groupby operation produced another DataFrame with a MultiIndex. Now I would like to visualize the frequencies in a mosaic plot. This is what I have tried:
rows=[
{"Mode":"ID", "SortBy":"Start", "SortDir":"ASC", "count":10},
{"Mode":"ID", "SortBy":"Start", "SortDir":"DESC", "count":100},
{"Mode":"FULL", "SortBy":"End", "SortDir":"DESC", "count":1000}
]
df=pd.DataFrame(rows)
hdf=df.groupby(["Mode", "SortBy", "SortDir"]).sum("count")
mosaic(hdf, index=hdf.index)
But it fails with the following error:
KeyError: "None of [MultiIndex([('FULL', 'End', 'DESC'),n ( 'ID', 'Start', 'ASC'),n ( 'ID', 'Start', 'DESC')],n names=['Mode', 'SortBy', 'SortDir'])] are in the [columns]"
I was able to produce a diagram using
mosaic(hdf, ["count"])
But this is obviously not what I want: it shows three same-sized rectangles labelled 10, 100, 1000, whereas I was expecting the categories Mode, SortBy, SortDir arranged around the axes and the rectangles reflecting the proportions of counts.