简体   繁体   English

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

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

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示例

My question is: how do I limit the range of y-axis of this plot? 我的问题是:如何限制该图的y轴范围? For example, I want the y-axis to be within [10, 40]. 例如,我希望y轴在[10,40]之内。 Is there any easy way to do this? 有没有简单的方法来做到这一点?

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))

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM