python - Using pandas.DataFrame.plot: sort legend by value -


i using following code create pie chart of pandas data frame, df.

data = df.groupby(["weather condition"])['hours per year'].sum() ax = data.plot(kind='pie', labels=none, legend=true) ax.get_legend().set_bbox_to_anchor((1.1, 1)) 

i following pie chart:

pie chart image

however, want legend sorted out highest values lowest values instead of alphabetically. know how go doing this? thanks.

i had similar problem , did following:

# first sort values of dataframe column you're interested data_sorted = data.sort_values(['hours per year']) 

then plot it:

# ...  data_sorted.plot(kind='pie', y='hours per year', legend = true) 

then legend should sorted want well.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -