Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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

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?

like image 730
Xin Avatar asked Oct 20 '15 03:10

Xin


People also ask

How do you change the range of the Y axis in a boxplot?

You can simply put an ylim = c(0, 5) in all your boxplot() call. This sets y-axis range (roughly) between 0 and 5.


1 Answers

It is standard matplotlib.pyplot:

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

Or simpler, as mwaskom comments below:

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

enter image description here

like image 194
Dave X Avatar answered Oct 17 '22 19:10

Dave X