如何在Seaborn点图上获取数据标签?

los*_*l29 6 python matplotlib scipy pandas seaborn

我有两个这样的数组:

Soldier_years = [1850, 1851, 1852, 1853, 1854, 1855, 1856, 1857, 1858, 1859, 1860, 1861, 1862, 1863, 1864, 1865, 1866, 1867, 1868, 1869, 1870]
num_records_yob = [7, 5, 8, 9, 15, 17, 23, 19, 52, 55, 73, 73, 107, 137, 65, 182, 228, 257, 477, 853, 2303]
Run Code Online (Sandbox Code Playgroud)

我试图将这些变成Seaborn点图,如下所示:

%matplotlib inline
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="darkgrid")

f, (ax) = plt.subplots(figsize=(12, 6), sharex=True)

sns.set_style("darkgrid")
ax = sns.pointplot(x=Soldier_years, y=num_records_yob)
Run Code Online (Sandbox Code Playgroud)

我得到一个像这样的点图:

Pointplot

这个情节几乎就是我想要的.如何获得每个点的数据标签以显示在各个点之上?

我试过了ax.patches,但它是空的.

我试图让它看起来像这样(但对于点图): 在此输入图像描述

Max*_*axU 9

你可以这样做:

[ax.text(p[0], p[1]+50, p[1], color='g') for p in zip(ax.get_xticks(), num_records_yob)]
Run Code Online (Sandbox Code Playgroud)

情节