There is the following code which produces a countplot with seaborn and annotating the precentage:
ax = sns.countplot(y=target_column, data=data, hue=target_column)
plt.title(f'Distribution of {target_column}')
plt.xlabel('Number of occurrences')
total = len(data[target_column])
for p in ax.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
ax.annotate(percentage, (x, y))
I wanted to add a legend and I know there is the hue parameter, but the result is that the legend box is overlapping the actual my bar and the percent annotation:
How do I change the location of the legend to the bottom-right of the plot?