I'm trying to annotate precentage in horizontal barplot with matplotlib. The problem is that when I try to add the precentage annotation I get error:
"module 'matplotlib.pyplot' has no attribute 'patches'
This is how I try to create the chart:
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
%matplotlib inline
sns.set(style="whitegrid")
#sns.set_color_codes("Spectral")
plt.figure(2, figsize=(20,15))
the_grid = GridSpec(2, 2)
plt.subplot(the_grid[0, 1], title='Original Dataset')
sns.barplot(x='count',y='land_cover_specific', data=df, palette='Spectral')
plt.xlabel('Count')
plt.ylabel('Land cover')
total = len(original)
print(total)
for p in plt.patches:
percentage = '{:.1f}%'.format(100 * p.get_width()/total)
x = p.get_x() + p.get_width() + 0.02
y = p.get_y() + p.get_height()/2
plt.annotate(percentage, (x, y))
plt.show()
I get the bar plot but I do not get the annotation due to this error.
My end goal: to add teh rpecentage of each bar count out of the total