matplotlib sort barh by values

16 views Asked by At

somehow I am unable to sort the values in descending order in horizontal bar chart.

occupation_stats = users_data.groupby('Occupation').agg(Occupation_Total=('User_Total','sum'),
                                                         Occupation_Mean=('User_Total','mean'),
                                                         Occupation_Num_Users=('User_Total','count'))


fig,axs = plt.subplots(1,3, figsize=(15,5))

for i,col in enumerate(occupation_stats):
  occupation_stats_sorted = occupation_stats[col].sort_values()
  axs[i].barh(occupation_stats_sorted.index.astype('object'), occupation_stats_sorted)
  axs[i].set_title('{}'.format(col))

The result is not sorted bar chart.

1

0

There are 0 answers