2

I have a swarmplot:

sns.swarmplot(y = "age gap corr", x = "cluster", 
              data = scatter_data, hue = 'group', dodge=True)

and I would like to adjust the transparency of the dots:

sns.swarmplot(y = "age gap corr", x = "cluster", 
              data = scatter_data, hue = 'group', dodge=True,
              scatter_kws = {'alpha': 0.1})

sns.swarmplot(y = "age gap corr", x = "cluster", 
              data = scatter_data, hue = 'group', dodge=True,
              plot_kws={'scatter_kws': {'alpha': 0.1}})

but neither of the above methods works. any help is appreciated.

Xin Niu
  • 533
  • 1
  • 5
  • 15

1 Answers1

3

You can simply input the alpha argument directly in the swarmplot function:

import seaborn as sns
df = sns.load_dataset('diamonds').sample(1000)
sns.swarmplot(data=df, x='cut', y='carat', hue='color', alpha=0.5)

enter image description here

The documentation for swarmplot states

kwargs : key, value mappings

Other keyword arguments are passed through to matplotlib.axes.Axes.scatter().

Thus, you don't need to use scatter_kws={...}.

Compare this to, e.g., sns.lmplot, which states

{scatter,line}_kws : dictionaries

Additional keyword arguments to pass to plt.scatter and plt.plot.

Community
  • 1
  • 1
Brendan
  • 3,901
  • 15
  • 23