Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do scatter_kws and line_kws do in seaborn lmplot

I am trying to understand the below code snippet.

sns.lmplot('num_items', 'total_value', data=log_carts, 
           scatter_kws={'s': 1, 'alpha': 0.1}, 
           line_kws={'lw': 2, 'color': '#4682b4'})

I understand that lmplot gives a regression line for the variables 'num_items' and 'total_value' from the dataframe 'log_carts' after plotting a scatter plot. But I couldn't understand what does scatter_kws and line_kws do to the plot. I searched the documentation of lmplot but it just says these two arguments are "additional keyword arguments to pass to plt.scatter and plt.plot" which doesn't help for me. I am looking for explanation for every element used in those two arguments.

like image 288
Sree Avatar asked Nov 12 '18 07:11

Sree


People also ask

What does SNS Lmplot do?

lmplot() method is used to draw a scatter plot onto a FacetGrid. Parameters : This method is accepting the following parameters that are described below: x, y: ( optional) This parameters are column names in data. data : This parameter is DataFrame .

What is the difference between Regplot and Lmplot?

While regplot() always shows a single relationship, lmplot() combines regplot() with FacetGrid to provide an easy interface to show a linear regression on “faceted” plots that allow you to explore interactions with up to three additional categorical variables.

What does SNS Implot () perform in Seaborn Library?

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 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.


2 Answers

Those are linked to the plot and line that appear in the figure. If we use scatter_kws={"s": 780} meaning the greater value given, the greater plot/node. If we use line_kws={"lw":5} meaning the greater the value given, the thicker the line.

for example:

sns.lmplot('Flour', 'Sugar', data=coba, hue='Type',
       palette='Set1', fit_reg=True, scatter_kws={"s": 780}, line_kws={"lw":5});

enter image description here

sns.lmplot('Flour', 'Sugar', data=coba, hue='Type',
       palette='Set1', fit_reg=True, scatter_kws={"s": 1000}, line_kws={"lw":30});

enter image description here

I took the program from https://github.com/adashofdata/muffin-cupcake

like image 132
Harun Ismail Avatar answered Oct 20 '22 20:10

Harun Ismail


I was also looking at how to improve the line styling of seaborn chart.

There are more options on to this.

For instance, to set some additional styling on line you could do (for a dashed line):

sns.lmplot('Flour', 'Sugar', data=coba, hue='Type', palette='Set1', fit_reg=True, scatter_kws={"s": 780},\
    line_kws={"lw":25, 'linestyle':'--'});

You could find all possible settings here: matplotlib docs for line styling

like image 1
bruszzz Avatar answered Oct 20 '22 19:10

bruszzz