Python 如何为seaborn boxplot设置y轴的范围?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33227473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:03:05  来源:igfitidea点击:

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

pythonmatplotlibboxplotseaborn

提问by Xin

From the official seaborn documentation, I learned that you can create a boxplot as below:

官方的 seaborn 文档中,我了解到您可以创建一个箱线图,如下所示:

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

Seaborn Boxplot Example

Seaborn 箱线图示例

My question is: how do I limit the range of y-axis of this plot? For example, I want the y-axis to be within [10, 40]. Is there any easy way to do this?

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

采纳答案by Dave X

It is standard matplotlib.pyplot:

它是标准的 matplotlib.pyplot:

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

Or simpler, as mwaskom comments below:

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

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

enter image description here

在此处输入图片说明