Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to add percentage in countplot

sns.set(style="whitegrid")
plt.figure(figsize=(8,5))
total = float(len(train_df))
ax = sns.countplot(x="event", hue="event", data=train_df)
plt.title('Data provided for each event', fontsize=20)
for p in ax.patches:
    percentage = '{:.1f}%'.format(100 * p.get_height()/total)
    x = p.get_x() + p.get_width()
    y = p.get_height()
    ax.annotate(percentage, (x, y),ha='center')
plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: python keyboard key codes 
Python :: zip python 
Python :: python see if a number is greater than other 
Python :: find max value in list python 
Python :: merging df vertically 
Python :: pandas reset index 
Python :: Extract bounding boxes OpenCV 
Python :: pandas print tabulate no index 
Python :: pandas apply lambda function with assign 
Python :: how to get prime numbers in a list in python using list comprehension 
Python :: How to take space-separated integer input in Python 3 
Python :: how to encrypt text in python 
Python :: roblox api python 
Python :: numpy savetext 
Python :: check if numpy array contains only duplicates 
Python :: Access item in a list of lists 
Python :: merge 2 dataframes pythom 
Python :: python sets 
Python :: tree to tuple python 
Python :: split into list into even chunks 
Python :: pandas filter rows that are in a list 
Python :: DLL Injection in python 
Python :: Python - Change List Items 
Python :: python str contains word 
Python :: making a return from your views 
Python :: python module install a whl 
Python :: json and python login system 
Python :: how to exit program in python 
Python :: urllib download file to folder 
Python :: numpy merge 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =