Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to add labels on bar of barchart seaborn

# Top 5 crops by year
sns.set_style('white')
fig, axs = plt.subplots(2, 2, figsize=(14, 8))

df_crg[df_crg.year == 2018].groupby('cropName').size().nlargest(5).plot(kind='barh', color='C0', title='2018', ax=axs[0, 0])
df_crg[df_crg.year == 2019].groupby('cropName').size().nlargest(5).plot(kind='barh', color='C1', title='2019', ax=axs[0, 1])
df_crg[df_crg.year == 2020].groupby('cropName').size().nlargest(5).plot(kind='barh', color='C2', title='2020', ax=axs[1, 0])
df_crg[df_crg.year == 2021].groupby('cropName').size().nlargest(5).plot(kind='barh', color='C3', title='2021', ax=axs[1, 1])

for ax in axs.flat:
    ax.bar_label(ax.containers[0], fmt='%.0f', label_type='edge', padding=2)
    ax.margins(x=0.1)
Comment

PREVIOUS NEXT
Code Example
Python :: python generator expression 
Python :: python min value index from an array 
Python :: ranking 
Python :: readlines 
Python :: make parameter optional python 
Python :: how to drop duplicate columns in pandas that dont have the same name? 
Python :: mean python 
Python :: print without newline 
Python :: Add label to histogram 
Python :: django login required 
Python :: python array join 
Python :: python towers of hanoi recursive 
Python :: python change function of object 
Python :: how to remove role from people with a reaction discord bot python 
Python :: python capitalize the entire string 
Python :: soustraire deux listes python 
Python :: read a csv file in pandas 
Python :: how to merge two column pandas 
Python :: discord.py get user id 
Python :: iterate over a list python 
Python :: decision tree classifier example 
Python :: request session python 
Python :: modify a list with for loop function in python 
Python :: poerty python macos 
Python :: dictionary changed size during iteration 
Python :: slicing of strings in python 
Python :: if else pandas dataframe 
Python :: python string encode 
Python :: matplotlib default style 
Python :: python dictoinary add value 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =