KDE Plot#

See also

API Documentation: plot_kde()

../_images/mpl_plot_kde.png
import matplotlib.pyplot as plt
import numpy as np

import arviz as az

az.style.use("arviz-doc")

data = az.load_arviz_data("centered_eight")

# Combine posterior draws for from xarray of (4,500) to ndarray (2000,)
y_hat = np.concatenate(data.posterior_predictive["obs"].values)

az.plot_kde(
    y_hat,
    label="Estimated Effect\n of SAT Prep",
    rug=True,
    plot_kwargs={"linewidth": 2},
    rug_kwargs={"alpha": 0.05},
)

plt.show()
import bokeh.plotting as bkp
import numpy as np

import arviz as az

data = az.load_arviz_data("centered_eight")

# Combine posterior draws for from xarray of (4,500) to ndarray (2000,)
y_hat = np.concatenate(data.posterior_predictive["obs"].values)

figure_kwargs = dict(height=500, width=500, output_backend="webgl")
ax = bkp.figure(**figure_kwargs)

ax = az.plot_kde(
    y_hat,
    label="Estimated Effect\n of SAT Prep",
    rug=True,
    plot_kwargs={"line_width": 2, "line_color": "black"},
    rug_kwargs={"line_color": "black"},
    backend="bokeh",
    ax=ax,
)