Is there a way to set transparency/alpha level in a seaborn pointplot?

Question:

I want to make a seaborn pointplot that has transparency so that I can clearly see the points located behind others of a different color.

I tried adding “alpha=0.3” to the call to pointplot and also tried the same within a catplot with kind=’point’; however, neither of these results in the desired transparency (no error message is produced either).

sns.pointplot(x='aamm', y='posrate', hue='AA:XX', hue_order=[1,0], data=data, dodge=True, palette=palette, alpha=0.3)

I was hoping to get a plot with transparent points, but instead, I got one with normal opaque points. The dodge option doesn’t seem to produce any noticeable effect either, in terms of separating overlapping points of different color.

Is there a way to add transparency to a seaborn pointplot or use something else to get a similar effect?

Thank you.

Asked By: chprgia

||

Answers:

To the extent of my knowledge there is no more an alpha parameter that can be directly set in seaborn.

You can do the following thou:

Sample dataframe

df = pd.DataFrame(np.random.randint(low=0, high=1000, size=(50, 5)))

Plotting

ax = sns.pointplot(x=0, y=1, data=df, dodge=True,plot_kws=dict(alpha=0.3))
plt.setp(ax.collections, alpha=.3) #for the markers
plt.setp(ax.lines, alpha=.3)       #for the lines

output

Answered By: CAPSLOCK
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.