Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python seaborn lmplot regplot for y-log scale fit

Tags:

python

seaborn

I was wondering why seaborn lmplot and regplot only has the option to do logx. I have a frequent use to linearly fit log(y) ~ x and the Y-axis should always be in log scale to show the correlation (as a convention).

Is this something that can be done in Seaborn?

An option of logy=True would be nice...

Thanks.

like image 273
Pan Yan Avatar asked Jul 17 '15 02:07

Pan Yan


People also ask

How do you set the log scale in Seaborn?

To make the x-axis to log scale, we first the make the scatter plot with Seaborn and save it to a variable and then use set function to specify 'xscale=log'. We see a linear pattern between lifeExp and gdpPercap. Now, the scatter plot makes more sense.

What is the difference between Regplot and Lmplot?

While regplot() always shows a single relationship, lmplot() combines regplot() with FacetGrid to show multiple fits using hue mapping or faceting.

What is the use of Seaborn Regplot () method?

regplot() : This method is used to plot data and a linear regression model fit. There are a number of mutually exclusive options for estimating the regression model.

What does the function SNS Lmplot () perform in Seaborn Library?

lmplot() method is used to draw a scatter plot onto a FacetGrid.


1 Answers

You can simply set the y-axis scale to log with:

import seaborn as sns; sns.set(color_codes=True)
tips = sns.load_dataset("tips")
ax = sns.regplot(x="total_bill", y="tip", data=tips)
ax.set_yscale('log')  # set_yscale is a function, not a string
like image 146
Constantino Avatar answered Sep 20 '22 09:09

Constantino