What do scatter_kws and line_kws do in seaborn lmplot

Viewed 20718

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.

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

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

Related