首页 > 解决方案 > plt.text() 与分类变量而不是数字对齐

问题描述

我认为这应该是相当直截了当的,但我遇到了麻烦。我怎样才能将标签集中在一个类别而不是一个绝对位置上。

EX:我希望中值标签位于“较低”类别的中心。 在此处输入图像描述

如何修改下面的代码以使此文本居中在“下”上方?

## plot strip plot
ax = sns.stripplot(x="Metric", y="Percent Error", data=dat,
                   jitter=0.3,
                   alpha = 0.5,
                   color = '#a54f7e',
                   linewidth=1,
                   edgecolor = '#a54f7e')

## Set title and axis
plt.title('Error Metrics')
ax.set(yscale="log")

## get median
lower_med = round(df['percent_error_lower'].median(),2)

## add text label 
plt.text(0, lower_med,'{:.2f} \n (Median)'.format(lower_med))

标签: pythonmatplotlibseaborn

解决方案


推荐阅读