如何在seaborn countplot中更改图例的位置?
如何在seaborn countplot中更改图例的位置?
以下是使用seaborn生成带有注释百分比的countplot的代码:
ax = sns.countplot(y=target_column, data=data, hue=target_column) plt.title(f'{target_column}的分布') plt.xlabel('出现次数') 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)) ax.legend(loc='lower right')
我想添加一个图例,我知道有hue参数,但结果是图例框重叠在实际的柱状图和百分比注释上。如何将图例的位置更改为图的右下角?