seaborn.
distplot
(a, bins=None, hist=True, kde=True, rug=False, fit=None, hist_kws=None, kde_kws=None, rug_kws=None, fit_kws=None, color=None, vertical=False, norm_hist=False, axlabel=None, label=None, ax=None)¶Flexibly plot a univariate distribution of observations.
This function combines the matplotlib hist
function (with automatic
calculation of a good default bin size) with the seaborn kdeplot()
and rugplot()
functions. It can also fit scipy.stats
distributions and plot the estimated PDF over the data.
Parameters: |
|
---|---|
Returns: |
|
See also
Examples
Show a default plot with a kernel density estimate and histogram with bin size determined automatically with a reference rule:
>>> import seaborn as sns, numpy as np
>>> sns.set(); np.random.seed(0)
>>> x = np.random.randn(100)
>>> ax = sns.distplot(x)
Use Pandas objects to get an informative axis label:
>>> import pandas as pd
>>> x = pd.Series(x, name="x variable")
>>> ax = sns.distplot(x)
Plot the distribution with a kernel density estimate and rug plot:
>>> ax = sns.distplot(x, rug=True, hist=False)
Plot the distribution with a histogram and maximum likelihood gaussian distribution fit:
>>> from scipy.stats import norm
>>> ax = sns.distplot(x, fit=norm, kde=False)
Plot the distribution on the vertical axis:
>>> ax = sns.distplot(x, vertical=True)
Change the color of all the plot elements:
>>> sns.set_color_codes()
>>> ax = sns.distplot(x, color="y")
Pass specific parameters to the underlying plot functions:
>>> ax = sns.distplot(x, rug=True, rug_kws={"color": "g"},
... kde_kws={"color": "k", "lw": 3, "label": "KDE"},
... hist_kws={"histtype": "step", "linewidth": 3,
... "alpha": 1, "color": "g"})