Seaborn KDE Plot: Alpha value of the line?

Viewed 1187

How do I access and set the alpha value of the line itself in Seaborn's KDE-plot?

I have tried the following to no effect:

sns.kdeplot(data = start_times, alpha = 0.2)
sns.kdeplot(data = start_times, line_kws = {'alpha':0.2})

ax = sns.kdeplot(data = start_times)
ax.set_alpha = 0.2

I can change alphas if I fill the KDEplot but I cant find how to change the alpha of the line.

2 Answers

The color of the line also contains the alpha of the line. The color can be set as an RGBA tuple of floats between [0,1].

To get a line with alpha=0.2 you can do

sns.kdeplot(data = start_times, color = (0.1, 0.3, 0.5, 0.2))

To actually set the alpha value (which is not the same as plotting a lighter color) you can do the following (assuming you plotted everything on ax):

for line in ax.get_lines():
    line.set_alpha(0.5)
plt.show()

(Example shows code for multiple overlayed KDE plots, but this should also work for a single line.)

Related