<p>约翰在评论中已经对答案进行了嘲弄。我只想解释和完成</p>
<p>以下是<code>seaborn.catplot</code>的<a href="https://seaborn.pydata.org/generated/seaborn.catplot.html" rel="nofollow noreferrer">documentation</a>关于排序的说明:</p>
<blockquote>
<p>As in the case with the underlying plot functions, if variables have a <em>categorical</em> data type, the levels of the categorical variables, and their order will be inferred from the objects. Otherwise you may have to use alter the dataframe sorting or use the function parameters (<code>orient</code>, <code>order</code>, <code>hue_order</code>, etc.) to set up the plot correctly.</p>
</blockquote>
<p>这意味着您可以使用<code>hue_order</code>参数来确保绘图的顺序符合您的要求:</p>
<blockquote>
<p><strong>order, hue_order: lists of strings, optional</strong><br/>
Order to plot the categorical levels in, otherwise the levels are inferred from the data objects.</p>
</blockquote>
<p>以下是如何在您的案例中使用它:</p>
<pre class="lang-py prettyprint-override"><code>sns.catplot(x='Pclass', y='Survived', hue='Sex', hue_order=['male', 'female'], data=train_df, kind='point', col='Embarked')
</code></pre>
<p>或者,正如文档中所描述并由JohanC指出的,您可以将列<code>train_df['Sex']</code>的类型转换为分类类型。然后通过<code>seaborn</code>推断顺序</p>