Python 海本直方图中的频率

Python 海本直方图中的频率,python,seaborn,Python,Seaborn,我有一个二手车的数据集。我已经做了一个按年龄划分的汽车数量的柱状图(以月为单位) 情节是这样的: 有什么方法可以描述绘图中每个箱子的频率值吗 PS:我知道我可以使用numpy直方图函数获取值,它是 np.histogram(df['Age'],bins=6) 基本上,我希望情节看起来像这样,我想是这样的: 您可以遍历属于ax的补丁,获取它们的位置和高度,并使用它们创建注释 导入matplotlib.pyplot作为plt 将numpy作为np导入 导入seaborn作为sns 作为pd进口熊

我有一个二手车的数据集。我已经做了一个按年龄划分的汽车数量的柱状图(以月为单位)

情节是这样的:

有什么方法可以描述绘图中每个箱子的频率值吗

PS:我知道我可以使用numpy直方图函数获取值,它是

np.histogram(df['Age'],bins=6)
基本上,我希望情节看起来像这样,我想是这样的:


您可以遍历属于ax的补丁,获取它们的位置和高度,并使用它们创建注释

导入matplotlib.pyplot作为plt
将numpy作为np导入
导入seaborn作为sns
作为pd进口熊猫
sns.set_style()
df=pd.DataFrame({'Age':np.random.triangular(1,80,80,1000).astype(np.int)})
ax=sns.distplot(df['Age'],kde=False,bin=6)
对于ax.patches中的p:
ax.annotate(f'{p.get_height():.0f}\n',
(p.get_x()+p.get_width()/2,p.get_height()),ha='center',va='center',color='crimson')
plt.show()

您可以遍历属于ax的补丁,获取它们的位置和高度,并使用它们创建注释

导入matplotlib.pyplot作为plt
将numpy作为np导入
导入seaborn作为sns
作为pd进口熊猫
sns.set_style()
df=pd.DataFrame({'Age':np.random.triangular(1,80,80,1000).astype(np.int)})
ax=sns.distplot(df['Age'],kde=False,bin=6)
对于ax.patches中的p:
ax.annotate(f'{p.get_height():.0f}\n',
(p.get_x()+p.get_width()/2,p.get_height()),ha='center',va='center',color='crimson')
plt.show()

这是否回答了您的问题?它对seaborn也有效吗?这能回答你的问题吗?它对seaborn也有效吗?
np.histogram(df['Age'],bins=6)