Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill area under curve in seaborn distribution plot

Tags:

People also ask

How do you fill a curve under a area in Python?

To fill the area under the curve, put x and y with ste="pre", using fill_between() method. Plot (x, y1) and (x, y2) lines using plot() method with drawstyle="steps" method. To display the figure, use show() method.

What does Distplot () mean in SNS Distplot ()?

distplot() The seaborn. distplot() function accepts the data variable as an argument and returns the plot with the density distribution. Example 1: import numpy as np import seaborn as sn import matplotlib.


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()?