如何设置 seaborn 箱线图的 y 轴范围?

How to set the range of y-axis for a seaborn boxplot?

official seaborn documentation,我了解到您可以创建如下箱线图:

import seaborn as sns
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
ax = sns.boxplot(x="day", y="total_bill", data=tips)

我的问题是:如何限制该图的y轴范围?例如,我希望 y 轴在 [10, 40] 范围内。有什么简单的方法可以做到这一点吗?

标准matplotlib.pyplot:

...
import matplotlib.pyplot as plt
plt.ylim(10, 40)

或者更简单,如下面的 mwaskom 评论:

ax.set(ylim=(10, 40))