48

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?

2 Answers 2

73

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})
4
  • 7
    Doesn't seem to work with kind="scatter", though : AttributeError: Unknown property line_kws. Mar 28, 2019 at 13:55
  • 1
    This unfortunately also applies the alpha to the legend. Is there any way around that? Oct 30, 2019 at 5:45
  • How can also annotate the actual pearson correlation value on each plot?
    – seralouk
    May 20, 2020 at 8:36
  • 1
    @seralouk I am afraid you will have to compute it outside of seaborn and then display it
    – famargar
    Jun 15, 2020 at 6:17
-1

Alpha can be set as a keyword argument as so:

g = sns.pairplot(df, kind='scatter', alpha=0.1)
1

Not the answer you're looking for? Browse other questions tagged or ask your own question.