2015-10-20 495 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