【发布时间】:2020-08-30 01:12:51
【问题描述】:
下面的代码会生成一个带有 seaborn 的计数图并注释百分比:
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))
我想添加一个图例,我知道有色相参数,但结果是图例框与实际的我的条和百分比注释重叠:
如何将图例的位置更改为绘图的右下角?
【问题讨论】:
标签: python python-3.x matplotlib seaborn legend