擅长:python、mysql、java
<p>这也可以通过从图本身导出中值而不必专门从数据中计算中值来实现</p>
<pre><code>box_plot = sns.boxplot(x="day", y="total_bill", data=tips)
ax = box_plot.axes
lines = ax.get_lines()
categories = ax.get_xticks()
for cat in categories:
# every 4th line at the interval of 6 is median line
# 0 -> p25 1 -> p75 2 -> lower whisker 3 -> upper whisker 4 -> p50 5 -> upper extreme value
y = round(lines[4+cat*6].get_ydata()[0],1)
ax.text(
cat,
y,
f'{y}',
ha='center',
va='center',
fontweight='bold',
size=10,
color='white',
bbox=dict(facecolor='#445A64'))
box_plot.figure.tight_layout()
</code></pre>
<p><a href="https://i.stack.imgur.com/anJlc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/anJlc.jpg" alt="enter image description here"/></a></p>