Seaborn.countplot : order categories by count?

前端 未结 2 1639
野趣味
野趣味 2021-02-03 19:09

I know that seaborn.countplot has the attribute order which can be set to determine the order of the categories. But what I would like to do is have the categories

2条回答
  •  别那么骄傲
    2021-02-03 19:39

    Most often, a seaborn countplot is not really necessary. Just plot with pandas bar plot:

    import seaborn as sns; sns.set(style='darkgrid')
    import matplotlib.pyplot as plt
    
    df = sns.load_dataset('titanic')
    
    df['class'].value_counts().plot(kind="bar")
    
    plt.show()
    

提交回复
热议问题