Skip to content

Use arviz for plotting #3338

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

Merged
merged 7 commits into from
Mar 2, 2019
Merged
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
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ Or via conda-forge:

conda install -c conda-forge pymc3

Plotting is done using `ArviZ <https://arviz-devs.github.io/arviz/>`__
which may be installed separately, or along with PyMC3:

::

pip install pymc3[plots]

The current development branch of PyMC3 can be installed from GitHub, also using ``pip``:

::
Expand Down
117 changes: 59 additions & 58 deletions docs/source/notebooks/BEST.ipynb

Large diffs are not rendered by default.

83 changes: 74 additions & 9 deletions pymc3/plots/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,74 @@
from .autocorrplot import autocorrplot
from .compareplot import compareplot
from .forestplot import forestplot
from .kdeplot import kdeplot
from .posteriorplot import plot_posterior, plot_posterior_predictive_glm
from .traceplot import traceplot
from .energyplot import energyplot
from .densityplot import densityplot
from .pairplot import pairplot
"""PyMC3 Plotting.

Plots are delegated to the ArviZ library, a general purpose library for
"exploratory analysis of Bayesian models." See https://arviz-devs.github.io/arviz/
for details on plots.
"""
import functools
import sys
import warnings
try:
import arviz as az
except ImportError: # arviz is optional, throw exception when used

class _ImportWarner:
__all__ = []

def __init__(self, attr):
self.attr = attr

def __call__(self, *args, **kwargs):
raise ImportError(
"ArviZ is not installed. In order to use `{0.attr}`:\npip install arviz".format(self)
)

class _ArviZ:
def __getattr__(self, attr):
return _ImportWarner(attr)


az = _ArviZ()

def map_args(func):
swaps = [
('varnames', 'var_names')
]
@functools.wraps(func)
def wrapped(*args, **kwargs):
for (old, new) in swaps:
if old in kwargs and new not in kwargs:
warnings.warn('Keyword argument `{old}` renamed to `{new}`, and will be removed in pymc3 3.8'.format(old=old, new=new))
kwargs[new] = kwargs.pop(old)
return func(*args, **kwargs)
return wrapped

# pymc3 custom plots: override these names for custom behavior
autocorrplot = map_args(az.plot_autocorr)
compareplot = map_args(az.plot_compare)
forestplot = map_args(az.plot_forest)
kdeplot = map_args(az.plot_kde)
plot_posterior = map_args(az.plot_posterior)
traceplot = map_args(az.plot_trace)
energyplot = map_args(az.plot_energy)
densityplot = map_args(az.plot_density)
pairplot = map_args(az.plot_pair)

from .posteriorplot import plot_posterior_predictive_glm


# Access to arviz plots: base plots provided by arviz
for plot in az.plots.__all__:
setattr(sys.modules[__name__], plot, map_args(getattr(az.plots, plot)))

__all__ = tuple(az.plots.__all__) + (
'autocorrplot',
'compareplot',
'forestplot',
'kdeplot',
'plot_posterior',
'traceplot',
'energyplot',
'densityplot',
'pairplot',
'plot_posterior_predictive_glm',
)
172 changes: 0 additions & 172 deletions pymc3/plots/artists.py

This file was deleted.

92 changes: 0 additions & 92 deletions pymc3/plots/autocorrplot.py

This file was deleted.

Loading