擅长:python、mysql、java
<p>可以通过调整绘图大小来执行此操作:</p>
<pre><code>g = sns.FacetGrid(df, row="Type", hue="Name", size=3, aspect=3)
g = g.map(sns.plt.plot, "Volume", "Index")
for ax in g.axes.flat:
box = ax.get_position()
ax.set_position([box.x0,box.y0,box.width*0.9,box.height])
sns.plt.legend(loc='center left',bbox_to_anchor=(1,0.5))
sns.plt.show()
</code></pre>
<p>示例:</p>
<pre><code>import seaborn as sns
tips = sns.load_dataset('tips')
# more informative values
condition = tips['smoker'] == 'Yes'
tips['smoking_status'] = ''
tips.loc[condition,'smoking_status'] = 'Smoker'
tips.loc[~condition,'smoking_status'] = 'Non-Smoker'
g = sns.FacetGrid(tips,row='sex',hue='smoking_status',size=3,aspect=3)
g = g.map(plt.scatter,'total_bill','tip')
for ax in g.axes.flat:
box = ax.get_position()
ax.set_position([box.x0,box.y0,box.width*0.85,box.height])
sns.plt.legend(loc='upper left',bbox_to_anchor=(1,0.5))
sns.plt.show()
</code></pre>
<p>结果:</p>
<p><a href="https://i.stack.imgur.com/lYk4u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lYk4u.png" alt="enter image description here"/></a></p>