Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log-log lmplot with seaborn

Tags:

python

seaborn

Can the function lmplot from Seaborn plot on a log-log scale? This is lmplot on a normal scale

import numpy as np import pandas as pd import seaborn as sns x =  10**arange(1, 10) y = 10** arange(1,10)*2 df1 = pd.DataFrame( data=y, index=x ) df2 = pd.DataFrame(data = {'x': x, 'y': y})  sns.lmplot('x', 'y', df2) 

sns.lmplot('x', 'y', df2)

like image 954
sjdh Avatar asked May 28 '14 13:05

sjdh


People also ask

How do you plot a 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. However, a lot of data points overlap on each other.

What is Lmplot Seaborn?

The lineplot (lmplot) is one of the most basic plots. It shows a line on a 2 dimensional plane. You can plot it with seaborn or matlotlib depending on your preference. The examples below use seaborn to create the plots, but matplotlib to show.

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

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

What is Regplot in Seaborn?

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.


1 Answers

If you just want to plot a simple regression, it will be easier to use seaborn.regplot. This seems to work (although I'm not sure where the y axis minor grid goes)

import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt  x = 10 ** np.arange(1, 10) y = x * 2 data = pd.DataFrame(data={'x': x, 'y': y})  f, ax = plt.subplots(figsize=(7, 7)) ax.set(xscale="log", yscale="log") sns.regplot("x", "y", data, ax=ax, scatter_kws={"s": 100}) 

enter image description here

If you need to use lmplot for other purposes, this is what comes to mind, but I'm not sure what's happening with the x axis ticks. If someone has ideas and it's a bug in seaborn, I'm happy to fix it:

grid = sns.lmplot('x', 'y', data, size=7, truncate=True, scatter_kws={"s": 100}) grid.set(xscale="log", yscale="log") 

enter image description here

like image 94
mwaskom Avatar answered Sep 19 '22 19:09

mwaskom