Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting ylim on seaborn boxplot

Is it possible to set ylim parameters on a seaborn boxplot?

as an example:

y = np.random.randn(300)
sns.boxplot (y=y)

Displays

boxplot

but if I try

ax.set_ylim=(-5, 5)

It makes no difference. Is it possible to set ylim values for a boxplot different from the default ones for a given dataset plot?

like image 206
chrisrb10 Avatar asked Jul 07 '17 12:07

chrisrb10


1 Answers

You use the axes-approach without having an axes-object.

Try (figure-based approach):

import matplotlib.pyplot as plt
plt.ylim([-5,5])

or probably better in your case:

ax = sns.boxplot (y=y)
ax.set_ylim([-5, 5])      # function! your code-sample is wrong here!

The docs here show the return-value of sns.boxplot.

And here is the general overview of matplotlib's objects.

like image 187
sascha Avatar answered Sep 30 '22 08:09

sascha