擅长:python、mysql、java
<p>可以使用<code>FacetGrid.axes</code>获取FacetGrid中使用的轴的列表,该列表返回使用的轴。然后,可以使用这些轴执行所有常规matplotlib操作,例如<a href="https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.axhline.html" rel="noreferrer">^{<cd2>}</a>用于水平线,或者<a href="https://matplotlib.org/api/_as_gen/matplotlib.pyplot.text.html" rel="noreferrer">^{<cd3>}</a>用于在轴上放置文本:</p>
<pre><code>import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
# Plot using Facegrid, separated by smoke
plt.style.use('ggplot')
g = sns.FacetGrid(tips, col="smoker", size=5, aspect=1.5)
g.map(sns.boxplot, "sex", "total_bill", palette='viridis', order=['Male', 'Female'])
ax1, ax2 = g.axes[0]
ax1.axhline(10, ls='--')
ax2.axhline(30, ls='--')
ax1.text(0.5,25, "Some text")
ax2.text(0.5,25, "Some text")
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/nz0eX.png" rel="noreferrer"><img src="https://i.stack.imgur.com/nz0eX.png" alt="enter image description here"/></a></p>