ax.patches 表示什么?
ax.patches 表示条形图中的每一个矩形
原图:
现在,我们为每个立柱增加对应的数值显示:
fig,ax = plt.subplots(figsize=(20,10), dpi=80)# 确定图的位置
ax.set_title("巡数分布") # 给图增加title
sns.countplot(x="totalsplist",data=tlj_data) #左图
#在直方图上显示具体数值
for p in ax.patches:# 在每个矩形上增添数值ax.annotate(f'\n{p.get_height()}', (p.get_x(), p.get_height()+50), color='black', size=15)plt.show()
增添完成后的效果图如图所示:
ax.patches 表示什么?
ax.patches 表示条形图中的每一个矩形
原图:
现在,我们为每个立柱增加对应的数值显示:
fig,ax = plt.subplots(figsize=(20,10), dpi=80)# 确定图的位置
ax.set_title("巡数分布") # 给图增加title
sns.countplot(x="totalsplist",data=tlj_data) #左图
#在直方图上显示具体数值
for p in ax.patches:# 在每个矩形上增添数值ax.annotate(f'\n{p.get_height()}', (p.get_x(), p.get_height()+50), color='black', size=15)plt.show()
增添完成后的效果图如图所示: