首页 > 解决方案 > 用数据值注释 seaborn 点图

问题描述

我想附加与以下代码生成的点图中的每个点相关的“值”。我的代码如下:

#data for pointplot with error bars
y = ['SC', 'GA', "FL", "MD"]
x = [.9, 1, 7, 4]
e = [.1, 0, .2, .3]

#plot
ax=sns.pointplot(x,y, join = False)
ax.errorbar(x,y, xerr=e, fmt='o', capsize=5)
ax.axvline(1, color='gray', linestyle='--')

#annotate points
for x,y in zip(x,y):
    ax.text(x, y,str(x),horizontalalignment='center',color='black',weight='light')
sns.despine()

结果如下所示在此处输入图像描述

但是,我的文本在数据点上运行,使结果看起来很笨拙。如何将文本中的“值”移动到数据点上方?

标签: python-3.xmatplotlibseaborn

解决方案


推荐阅读