I have two variables
x = [1.883830, 7.692308,8.791209, 9.262166]
y = [5.337520, 4.866562, 2.825746, 6.122449]
And I want to fit a Gaussian distribution using the seaborn wrapped for matplotlib. It seems like the sns.distplot
function is the best way to do this, but I can't figure out how to fill in the area under the curve. Help?
fig, ax = plt.subplots(1)
sns.distplot(x,kde_kws={"shade":True}, kde=False, fit=stats.gamma, hist=None, color="red", label="2016", fit_kws={'color':'red'});
sns.distplot(y,kde_kws={"shade":True}, kde=False, fit=stats.gamma, hist=None, color="blue", label="2017", fit_kws={'color':'blue'})
I think the "shade" argument could be part of the fit_kws
argument but I haven't gotten this to work.
Another option would be to use ax.fill()
?
Yes, the
shade
argument is not supported forfit_kws
unlike for thekde_kws
. But as you guessed, we can fill the area under the two curves usingax.fill_between()
. We will have to get the lines from theax
object and their x-y data and then use that to fill the area under the curves. Here is an example.The result is shown below: