Sorted bar charts with pandas/matplotlib or seaborn

后端 未结 2 1158
时光说笑
时光说笑 2020-12-10 06:43

I have a dataset of 5000 products with 50 features. One of the column is \'colors\' and there are more than 100 colors in the column. I\'m trying to plot a bar chart to show

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-10 07:20

    An easy trick might be to invert the y axis of your plot, rather than futzing with the data:

    s = pd.Series(np.random.choice(list(string.uppercase), 1000))
    counts = s.value_counts()
    ax = counts.iloc[:10].plot(kind="barh")
    ax.invert_yaxis()
    

    enter image description here

    Seaborn barplot doesn't currently support horizontally oriented bars, but if you want to control the order the bars appear in you can pass a list of values to the x_order param. But I think it's easier to use the pandas plotting methods here, anyway.

提交回复
热议问题