擅长:python、mysql、java
<p>直接从轴的补丁中获得:</p>
<pre><code>for p in ax.patches:
ax.annotate(str(p.get_height()), (p.get_x() * 1.005, p.get_height() * 1.005))
</code></pre>
<p>您可能需要调整字符串格式和偏移量以使其居中,也可以使用<code>p.get_width()</code>中的宽度,但这应该可以帮助您开始。它可能不适用于堆叠条形图,除非您跟踪某个位置的偏移。</p>