Following simple code:
import numpy as np
import seaborn as sns
dist = np.random.normal(loc=0, scale=1, size=1000)
ax = sns.kdeplot(dist, shade=True);
Yields the following image:
I would like to only shade everything right (or left to some x value). What is the simplest way? I am ready to use something other than Seaborn.
Using seaborn is often fine for standard plots, but when some customized requirements come into play, falling back to matplotlib is often easier.
So one may first calculate the kernel density estimate and then plot it in the region of interest.
After calling
ax = sns.kdeplot(dist, shade=True)
, the last line inax.get_lines()
corresponds to the kde density curve:You can extract the data corresponding to that curve using
line.get_data
:Once you have the data, you can, for instance, shade the region corresponding to
x > 0
by selecting those points and callingax.fill_between
: