Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adjust transparency (alpha) in seaborn pairplot?

I can create beatiful scatter plot with seaborns regplot, obtain the right level of transparency through the scatter_kws as in

sns.regplot(x='logAssets', y='logLTIFR', lowess=True, data=df, scatter_kws={'alpha':0.15}, line_kws={'color': 'red'}) 

and obtain this:

enter image description here

Is there an option in a seaborn pairplot to tweak transparency?

like image 269
famargar Avatar asked Nov 09 '17 10:11

famargar


People also ask

What is Alpha in Seaborn?

To control the transparency of plots, we can use the alpha argument within the plot function. By default, its value is 1. The value of this parameter ranges from 0 to 1, with the plot getting more transparent and invisible as the value reaches 0.

What is Pairplot in Seaborn?

seaborn.pairplot() To plot multiple pairwise bivariate distributions in a dataset, you can use the pairplot() function. This shows the relationship for (n, 2) combination of variable in a DataFrame as a matrix of plots and the diagonal plots are the univariate plots.


1 Answers

Ok I was very close to the solution. Seaborn pairplots have plot_kws that takes as arguments a dictionary of the kind of modifications you would do in a regplot. The following line is exactly what I needed:

g = sns.pairplot(df, kind='reg', plot_kws={'line_kws':{'color':'red'}, 'scatter_kws': {'alpha': 0.1}}) 

And this is the outcome:

enter image description here

If you don't do the regression but just the scatter plot (kind='scatter'), within plot keywords you don't have to do the division between line and scatter keywords:

g = sns.pairplot(df, kind='scatter', plot_kws={'alpha':0.1}) 
like image 178
famargar Avatar answered Sep 28 '22 03:09

famargar