2015-10-20 1699 views
8

official seaborn documentation,我了解到,您可以创建如下的箱线图:如何设置seaborn boxplot的y轴范围?

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

我的问题是:我怎么限制该地块的y轴的范围是多少?例如,我希望y轴在[10,40]之内。有没有简单的方法来做到这一点?

回答

17

这是标准的matplotlib.pyplot:

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

enter image description here

+9

或者,更好的,'ax.set(ylim =(10,40))' – mwaskom

+0

为什么这更好,@mwaskom? – MERose

+1

mwaskom可能更喜欢matplotlib(在对象上调用方法)的面向对象方面,而不是matplotlib.pyplot需要的更多过程方法(以特定顺序调用全局函数)。 – NasaGeek