How to prevent alphabetical sorting for python bars with matplotlib?

前端 未结 2 561
忘了有多久
忘了有多久 2020-12-20 14:36

I\'m plotting some categorical data using a bar chart. Matplotlib keeps sorting my x-axis alphabetically even when I sort my dataframe values. Here\'s my code :



        
2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-20 15:20

    I answer my own question because I found a way around but it needs one more line of code to get to the same result and I don't like that :

    summary.plot(kind='bar', ax=new_ax, color=my_colors, width=0.8)
    fig3.autofmt_xdate(bottom=0.2, rotation=0, ha='center')
    

    Second line is needed because summary.plot() changes the orientation of the xticklabels to vertical...

提交回复
热议问题