擅长:python、mysql、java
<p>你可以做些更简单的事</p>
<pre><code>plt.figure(figsize=(4, 3))
plot = sns.catplot(x='Sex', y='count', kind='bar', data=titanic_df)
# plot.ax gives the axis object
# plot.ax.patches gives list of bars that can be access using index starting at 0
for i, bar in enumerate(plot.ax.patches):
h = bar.get_height()
plot.ax.text(
i, # bar index (x coordinate of text)
h+10, # y coordinate of text
'{}'.format(int(h)), # y label
ha='center',
va='center',
fontweight='bold',
size=14)
</code></pre>
<p><a href="https://i.stack.imgur.com/jWcrw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jWcrw.png" alt="enter image description here"/></a></p>