I'm trying to create a density plot with a gradient fill in python like this:
I've attempted to do so using this code:
plt.figure(figsize=(6, 1))
sns.kdeplot(data=df, x='Overall Rating', fill=True, palette='viridis')
...and
sns.kdeplot(data=df, x='Overall Rating', fill=True, cmap='viridis')
Neither work, both outputting this plot:
I've searched all over for a method to do this in python, but no luck. I've tried implementing the methods from this answer by @Diziet Asahi but can't wrap my head around it. Any help would really be appreciated!


You just need to grab the ax:
ax = sns.kdeplot(...)and then execute the inner part of theforloop in @Diziet Asahi's solution with thatax.