Plotting categorical data with pandas and matplotlib

前端 未结 5 1950
有刺的猬
有刺的猬 2020-11-28 23:27

I have a data frame with categorical data:

     colour  direction
1    red     up
2    blue    up
3    green   down
4    red     left
5    red     right
6            


        
5条回答
  •  感动是毒
    2020-11-28 23:56

    You might find useful mosaic plot from statsmodels. Which can also give statistical highlighting for the variances.

    from statsmodels.graphics.mosaicplot import mosaic
    plt.rcParams['font.size'] = 16.0
    mosaic(df, ['direction', 'colour']);
    

    enter image description here

    But beware of the 0 sized cell - they will cause problems with labels.

    See this answer for details

提交回复
热议问题