arviz.plot_kde

arviz.plot_kde(values, values2=None, cumulative=False, rug=False, label=None, bw=4.5, quantiles=None, rotated=False, contour=True, fill_last=True, textsize=None, plot_kwargs=None, fill_kwargs=None, rug_kwargs=None, contour_kwargs=None, ax=None, legend=True)[source]

1D or 2D KDE plot taking into account boundary conditions.

Parameters:
values : array-like

Values to plot

values2 : array-like, optional

Values to plot. If present, a 2D KDE will be estimated

cumulative : bool

If true plot the estimated cumulative distribution function. Defaults to False. Ignored for 2D KDE

rug : bool

If True adds a rugplot. Defaults to False. Ignored for 2D KDE

label : string

Text to include as part of the legend

bw : float

Bandwidth scaling factor for 1D KDE. Should be larger than 0. The higher this number the smoother the KDE will be. Defaults to 4.5 which is essentially the same as the Scott’s rule of thumb (the default rule used by SciPy).

quantiles : list

Quantiles in ascending order used to segment the KDE. Use [.25, .5, .75] for quartiles. Defaults to None.

rotated : bool

Whether to rotate the 1D KDE plot 90 degrees.

contour : bool

If True plot the 2D KDE using contours, otherwise plot a smooth 2D KDE. Defaults to True.

fill_last : bool

If True fill the last contour of the 2D KDE plot. Defaults to True.

textsize: float

Text size scaling factor for labels, titles and lines. If None it will be autoscaled based on figsize.

plot_kwargs : dict

Keywords passed to the pdf line of a 1D KDE.

fill_kwargs : dict

Keywords passed to the fill under the line (use fill_kwargs={‘alpha’: 0} to disable fill). Ignored for 2D KDE

rug_kwargs : dict

Keywords passed to the rug plot. Ignored if rug=False or for 2D KDE Use space keyword (float) to control the position of the rugplot. The larger this number the lower the rugplot.

contour_kwargs : dict

Keywords passed to the contourplot. Ignored for 1D KDE.

ax : matplotlib axes
legend : bool

Add legend to the figure. By default True.

Returns:
ax : matplotlib axes

Examples

Plot default KDE

>>> import arviz as az
>>> non_centered = az.load_arviz_data('non_centered_eight')
>>> mu_posterior = np.concatenate(non_centered.posterior["mu"].values)
>>> az.plot_kde(mu_posterior)
../_images/arviz-plot_kde-1.png

Plot KDE with rugplot

>>> az.plot_kde(mu_posterior, rug=True)
../_images/arviz-plot_kde-2.png

Plot a cumulative distribution

>>> az.plot_kde(mu_posterior, cumulative=True)
../_images/arviz-plot_kde-3.png

Rotate plot 90 degrees

>>> az.plot_kde(mu_posterior, rotated=True)
../_images/arviz-plot_kde-4.png

Plot 2d contour KDE

>>> tau_posterior = np.concatenate(non_centered.posterior["tau"].values)
>>> az.plot_kde(mu_posterior, values2=tau_posterior)
../_images/arviz-plot_kde-5.png

Remove fill for last contour in 2d KDE

>>> az.plot_kde(mu_posterior, values2=tau_posterior, fill_last=False)
../_images/arviz-plot_kde-6.png

Plot 2d smooth KDE

>>> az.plot_kde(mu_posterior, values2=tau_posterior, contour=False)
../_images/arviz-plot_kde-7.png