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

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

Ansible warning on jinja2 braces on when -

html - How to custom Bootstrap grid height? -