Matplotlib Example Gallery

Note

These examples are adapted from ArviZ's matplotlib gallery.

Autocorrelation Plot

using PyPlot
using ArviZ

ArviZ.use_style("arviz-darkgrid")

data = load_arviz_data("centered_eight")
plot_autocorr(data; var_names=("tau", "mu"))

gcf()

See plot_autocorr

Bayesian P-Value Posterior Plot

using PyPlot
using ArviZ

ArviZ.use_style("arviz-darkgrid")

data = load_arviz_data("regression1d")
plot_bpv(data)

gcf()

See plot_bpv

Bayesian P-Value with Median T Statistic Posterior Plot

using PyPlot
using ArviZ

ArviZ.use_style("arviz-darkgrid")

data = load_arviz_data("regression1d")
plot_bpv(data; kind="t_stat", t_stat="0.5")

gcf()

See plot_bpv

Compare Plot

using PyPlot
using ArviZ

ArviZ.use_style("arviz-darkgrid")

model_compare = compare(
    Dict(
        "Centered 8 schools" => load_arviz_data("centered_eight"),
        "Non-centered 8 schools" => load_arviz_data("non_centered_eight"),
    ),
)
plot_compare(model_compare; figsize=(12, 4))

gcf()

See compare, plot_compare

Density Plot

using PyPlot
using ArviZ

ArviZ.use_style("arviz-darkgrid")

centered_data = load_arviz_data("centered_eight")
non_centered_data = load_arviz_data("non_centered_eight")
plot_density(
    [centered_data, non_centered_data];
    data_labels=["Centered", "Non Centered"],
    var_names=["theta"],
    shade=0.1,
)

gcf()

See plot_density

Dist Plot

using Random
using Distributions
using PyPlot
using ArviZ

Random.seed!(308)

ArviZ.use_style("arviz-darkgrid")

a = rand(Poisson(4), 1000)
b = rand(Normal(0, 1), 1000)
_, ax = plt.subplots(1, 2; figsize=(10, 4))
plot_dist(a; color="C1", label="Poisson", ax=ax[1])
plot_dist(b; color="C2", label="Gaussian", ax=ax[2])

gcf()

See plot_dist

ELPD Plot

using PyPlot
using ArviZ

ArviZ.use_style("arviz-darkgrid")

d1 = load_arviz_data("centered_eight")
d2 = load_arviz_data("non_centered_eight")
plot_elpd(Dict("Centered eight" => d1, "Non centered eight" => d2); xlabels=true)

gcf()

See plot_elpd

Energy Plot

using PyPlot
using ArviZ

ArviZ.use_style("arviz-darkgrid")

data = load_arviz_data("centered_eight")
plot_energy(data; figsize=(12, 8))

gcf()

See plot_energy

ESS Evolution Plot

using PyPlot
using ArviZ

ArviZ.use_style("arviz-darkgrid")

idata = load_arviz_data("radon")
plot_ess(idata; var_names=["b"], kind="evolution")

gcf()

See plot_ess

ESS Local Plot

using PyPlot
using ArviZ

ArviZ.use_style("arviz-darkgrid")

idata = load_arviz_data("non_centered_eight")
plot_ess(idata; var_names=["mu"], kind="local", marker="_", ms=20, mew=2, rug=true)

gcf()

See plot_ess

ESS Quantile Plot

using PyPlot
using ArviZ

ArviZ.use_style("arviz-darkgrid")

idata = load_arviz_data("radon")
plot_ess(idata; var_names=["sigma"], kind="quantile", color="C4")

gcf()

See plot_ess

Forest Plot

using PyPlot
using ArviZ

ArviZ.use_style("arviz-darkgrid")

centered_data = load_arviz_data("centered_eight")
non_centered_data = load_arviz_data("non_centered_eight")
plot_forest(
    [centered_data, non_centered_data];
    model_names=["Centered", "Non Centered"],
    var_names=["mu"],
)
title("Estimated theta for eight schools model")

gcf()

See plot_forest

Ridge Plot

using PyPlot
using ArviZ

ArviZ.use_style("arviz-darkgrid")

rugby_data = load_arviz_data("rugby")
plot_forest(
    rugby_data;
    kind="ridgeplot",
    var_names=["defs"],
    linewidth=4,
    combined=true,
    ridgeplot_overlap=1.5,
    colors="blue",
    figsize=(9, 4),
)
title("Relative defensive strength\nof Six Nation rugby teams")

gcf()

See plot_forest

Plot HDI

using Random
using PyPlot
using ArviZ

Random.seed!(308)

ArviZ.use_style("arviz-darkgrid")

x_data = randn(100)
y_data = 2 .+ x_data .* 0.5
y_data_rep = 0.5 .* randn(200, 100) .+ transpose(y_data)
plot(x_data, y_data; color="C6")
plot_hdi(x_data, y_data_rep; color="k", plot_kwargs=Dict("ls" => "--"))

gcf()

See plot_hdi

Joint Plot

using PyPlot
using ArviZ

ArviZ.use_style("arviz-darkgrid")

data = load_arviz_data("non_centered_eight")
plot_pair(
    data;
    var_names=["theta"],
    coords=Dict("school" => ["Choate", "Phillips Andover"]),
    kind="hexbin",
    marginals=true,
    figsize=(10, 10),
)

gcf()