Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding MCSE Plot #79

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/source/api/backend/none.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
============
None backend
============

.. automodule:: arviz_plots.backend.none


Object creation and I/O
.......................

.. autosummary::
:toctree: generated/

create_plotting_grid
show

Geoms
.....

.. autosummary::
:toctree: generated/

line
scatter
text

Plot appeareance
................

.. autosummary::
:toctree: generated/

title
ylabel
xlabel
xticks
yticks
ticklabel_props
remove_ticks
remove_axis

Legend
......

.. autosummary::
:toctree: generated/

legend
48 changes: 48 additions & 0 deletions docs/source/api/backend/plotly.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
==============
Plotly backend
==============

.. automodule:: arviz_plots.backend.plotly


Object creation and I/O
.......................

.. autosummary::
:toctree: generated/

create_plotting_grid
show

Geoms
.....

.. autosummary::
:toctree: generated/

line
scatter
text

Plot appeareance
................

.. autosummary::
:toctree: generated/

title
ylabel
xlabel
xticks
yticks
ticklabel_props
remove_ticks
remove_axis

Legend
......

.. autosummary::
:toctree: generated/

legend
1 change: 1 addition & 0 deletions docs/source/gallery/backreferences.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"plot_forest": [{"basename": "plot_forest_ess", "refname": "gallery_forest_ess", "title": "Forest plot with ESS", "description": "Multiple panel visualization with a forest plot and ESS information"}, {"basename": "plot_forest", "refname": "gallery_forest", "title": "Forest plot", "description": "Default forest plot with marginal distribution summaries"}, {"basename": "plot_forest_shade", "refname": "gallery_forest_shade", "title": "Forest plot with shading", "description": "Forest plot marginal summaries with row shading to enhance reading"}, {"basename": "plot_forest_models", "refname": "gallery_forest_models", "title": "Forest plot comparison", "description": "Forest plot summaries for 1D marginal distributions"}, {"basename": "plot_forest_pp_obs", "refname": "gallery_forest_pp_obs", "title": "Posterior predictive and observations forest plot", "description": "Overlay of forest plot for the posterior predictive samples and the actual observations"}], "plot_dist": [{"basename": "plot_dist_ecdf", "refname": "gallery_dist_ecdf", "title": "ECDF plot", "description": "Facetted ECDF plots for 1D marginals of the distribution"}, {"basename": "plot_dist_hist", "refname": "gallery_dist_hist", "title": "Histogram plot", "description": "Facetted histogram plots for 1D marginals of the distribution"}, {"basename": "plot_dist_kde", "refname": "gallery_dist_kde", "title": "KDE plot", "description": "Facetted KDE plots for 1D marginals of the distribution"}, {"basename": "plot_dist_models", "refname": "gallery_dist_models", "title": "Marginal distribution comparison plot", "description": "Full marginal distribution comparison between different models"}], "plot_mcse": [{"basename": "plot_mcse", "refname": "gallery_mcse", "title": "MCSE Quantile plot", "description": "Facetted quantile MCSE plot"}, {"basename": "plot_mcse_errorbar", "refname": "gallery_mcse_errorbar", "title": "MCSE Quantile plot with errorbars", "description": "Facetted quantile MCSE plot with errorbars"}, {"basename": "plot_mcse_models", "refname": "gallery_mcse_models", "title": "MCSE comparison plot", "description": "Full MCSE comparison between different models"}], "plot_trace": [{"basename": "plot_trace", "refname": "gallery_trace", "title": "Trace plot", "description": "Facetted plot with MCMC traces for each variable"}]}
24 changes: 24 additions & 0 deletions docs/source/gallery/inference_diagnostics/plot_mcse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
# MCSE Quantile plot

Facetted quantile MCSE plot

---

:::{seealso}
API Documentation: {func}`~arviz_plots.plot_mcse`
:::
"""

from arviz_base import load_arviz_data

import arviz_plots as azp

azp.style.use("arviz-clean")

data = load_arviz_data("centered_eight")
pc = azp.plot_mcse(
data,
backend="none", # change to preferred backend
)
pc.show()
25 changes: 25 additions & 0 deletions docs/source/gallery/inference_diagnostics/plot_mcse_errorbar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
# MCSE Quantile plot with errorbars

Facetted quantile MCSE plot with errorbars

---

:::{seealso}
API Documentation: {func}`~arviz_plots.plot_mcse`
:::
"""

from arviz_base import load_arviz_data

import arviz_plots as azp

azp.style.use("arviz-clean")

data = load_arviz_data("centered_eight")
pc = azp.plot_mcse(
data,
errorbar=True,
backend="none", # change to preferred backend
)
pc.show()
25 changes: 25 additions & 0 deletions docs/source/gallery/inference_diagnostics/plot_mcse_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
# MCSE comparison plot

Full MCSE comparison between different models

---

:::{seealso}
API Documentation: {func}`~arviz_plots.plot_mcse`
:::
"""

from arviz_base import load_arviz_data

import arviz_plots as azp

azp.style.use("arviz-clean")

c = load_arviz_data("centered_eight")
n = load_arviz_data("non_centered_eight")
pc = azp.plot_mcse(
{"Centered": c, "Non Centered": n},
backend="none", # change to preferred backend
)
pc.show()
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
# MCSE comparison plot with errorbars

Full MCSE comparison between different models with errorbars

---

:::{seealso}
API Documentation: {func}`~arviz_plots.plot_mcse`
:::
"""

from arviz_base import load_arviz_data

import arviz_plots as azp

azp.style.use("arviz-clean")

c = load_arviz_data("centered_eight")
n = load_arviz_data("non_centered_eight")
pc = azp.plot_mcse(
{"Centered": c, "Non Centered": n},
errorbar=True,
backend="none", # change to preferred backend
)
pc.show()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ classifiers = [
dynamic = ["version", "description"]
dependencies = [
"arviz-base==0.2",
"arviz-stats[xarray]==0.2",
"arviz-stats[xarray] @ git+https://github.com/arviz-devs/arviz-stats",
]

[tool.flit.module]
Expand Down
43 changes: 43 additions & 0 deletions src/arviz_plots/backend/bokeh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,49 @@ def scatter(
return target.scatter(np.atleast_1d(x), np.atleast_1d(y), **kwargs)


def errorbar(
x,
y,
error,
target,
*,
size=unset,
marker=unset,
color=unset,
facecolor=unset,
edgecolor=unset,
width=unset,
**artist_kws,
):
"""Interface to bokeh for an errorbar plot."""
if color is not unset:
if facecolor is unset and edgecolor is unset:
facecolor = color
edgecolor = color
elif facecolor is unset:
facecolor = color
elif edgecolor is unset:
edgecolor = color
kwargs = {
"size": size,
"marker": marker,
"fill_color": facecolor,
"line_color": edgecolor,
"line_width": width,
}
kwargs = _filter_kwargs(kwargs, artist_kws)
if marker == "|":
kwargs["marker"] = "dash"
kwargs["angle"] = np.pi / 2

target.scatter(np.atleast_1d(x), np.atleast_1d(y), **kwargs)

x_err = list(zip(x, x))
y_err = [(y_i - err, y_i + err) for y_i, err in zip(y, error)]
target.multi_line(xs=x_err, ys=y_err, **kwargs)
return target


def text(
x,
y,
Expand Down
36 changes: 36 additions & 0 deletions src/arviz_plots/backend/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,42 @@ def scatter(
return target.scatter(x, y, **_filter_kwargs(kwargs, None, artist_kws))


def errorbar(
x,
y,
error,
target,
*,
size=unset,
marker=unset,
color=unset,
facecolor=unset,
edgecolor=unset,
width=unset,
**artist_kws,
):
"""Interface to matplotlib for an errorbar plot."""
artist_kws.setdefault("zorder", 2)
fillable_marker = (marker is unset) or (marker in Line2D.filled_markers)
if color is not unset:
if facecolor is unset and edgecolor is unset:
facecolor = color
if fillable_marker:
edgecolor = color
elif facecolor is unset:
facecolor = color
elif edgecolor is unset and fillable_marker:
edgecolor = color
kwargs = {
"capsize": size,
"marker": marker,
"markerfacecolor": facecolor,
"markeredgecolor": edgecolor,
"elinewidth": width,
}
return target.errorbar(x, y, error, **_filter_kwargs(kwargs, None, artist_kws))


def text(
x,
y,
Expand Down
43 changes: 43 additions & 0 deletions src/arviz_plots/backend/none/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,49 @@ def scatter(
return artist_element


def errorbar(
x,
y,
error,
target,
*,
size=unset,
marker=unset,
color=unset,
facecolor=unset,
edgecolor=unset,
width=unset,
**artist_kws,
):
"""Interface to an errorbar plot."""
if color is not unset:
if facecolor is unset and edgecolor is unset:
facecolor = color
edgecolor = color
elif facecolor is unset:
facecolor = color
elif edgecolor is unset:
edgecolor = color
kwargs = {
"capsize": size,
"marker": marker,
"markerfacecolor": facecolor,
"markeredgecolor": edgecolor,
"elinewidth": width,
}
if not ALLOW_KWARGS and artist_kws:
raise ValueError("artist_kws not empty")
artist_element = {
"function": "errorbar",
"x": np.atleast_1d(x),
"y": np.atleast_1d(y),
"error": np.atleast_1d(error),
**_filter_kwargs(kwargs, artist_kws),
}
target.append(artist_element)
return artist_element


def text(
x,
y,
Expand Down
2 changes: 2 additions & 0 deletions src/arviz_plots/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .compareplot import plot_compare
from .distplot import plot_dist
from .forestplot import plot_forest
from .mcseplot import plot_mcse
from .ridgeplot import plot_ridge
from .tracedistplot import plot_trace_dist
from .traceplot import plot_trace
Expand All @@ -14,4 +15,5 @@
"plot_trace",
"plot_trace_dist",
"plot_ridge",
"plot_mcse",
]
Loading