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.
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 .
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.
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.
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.
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});
sns.lmplot('Flour', 'Sugar', data=coba, hue='Type',
palette='Set1', fit_reg=True, scatter_kws={"s": 1000}, line_kws={"lw":30});
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With