diff --git a/CHANGELOG.md b/CHANGELOG.md index 1423f1761f..3a1c981c59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ ### New features * Integrate jointplot into pairplot, add point-estimate and overlay of plot kinds #1079 ### Maintenance and fixes - +* Fixed behaviour of `credible_interval=None` in `plot_posterior` (#1115) +* Fixed hist kind of `plot_dist` with multidimensional input (#1115) ### Deprecation ### Documentation diff --git a/arviz/plots/backends/bokeh/distplot.py b/arviz/plots/backends/bokeh/distplot.py index 42f8917368..987c616169 100644 --- a/arviz/plots/backends/bokeh/distplot.py +++ b/arviz/plots/backends/bokeh/distplot.py @@ -115,7 +115,7 @@ def _histplot_bokeh_op(values, values2, rotated, ax, hist_kwargs): if bins is None: bins = get_bins(values) density = hist_kwargs.pop("density", True) - hist, edges = np.histogram(values, density=density, bins=bins) + hist, edges = np.histogram(np.asarray(values).flatten(), density=density, bins=bins) if hist_kwargs.pop("cumulative", False): hist = np.cumsum(hist) hist /= hist[-1] diff --git a/arviz/plots/backends/matplotlib/distplot.py b/arviz/plots/backends/matplotlib/distplot.py index 1c56e27883..193bcc98f5 100644 --- a/arviz/plots/backends/matplotlib/distplot.py +++ b/arviz/plots/backends/matplotlib/distplot.py @@ -1,10 +1,11 @@ """Matplotlib distplot.""" import warnings import matplotlib.pyplot as plt - +import numpy as np from . import backend_show from ...kdeplot import plot_kde from ...plot_utils import matplotlib_kwarg_dealiaser +from ...plot_utils import get_bins def plot_dist( @@ -91,8 +92,10 @@ def _histplot_mpl_op(values, values2, rotated, ax, hist_kwargs): raise NotImplementedError("Insert hexbin plot here") bins = hist_kwargs.pop("bins") + if bins is None: + bins = get_bins(values) + ax.hist(np.asarray(values).flatten(), bins=bins, **hist_kwargs) - ax.hist(values, bins=bins, **hist_kwargs) if rotated: ax.set_yticks(bins[:-1]) else: diff --git a/arviz/plots/distplot.py b/arviz/plots/distplot.py index cb2234db6e..af7aefc985 100644 --- a/arviz/plots/distplot.py +++ b/arviz/plots/distplot.py @@ -1,7 +1,9 @@ # pylint: disable=unexpected-keyword-arg """Plot distribution as histogram or kernel density estimates.""" +import xarray as xr from .plot_utils import get_bins, get_plotting_function, matplotlib_kwarg_dealiaser +from ..data import InferenceData from ..rcparams import rcParams @@ -142,6 +144,13 @@ def plot_dist( >>> az.plot_dist(b, rug=True, quantiles=[.25, .5, .75], cumulative=True) """ + if isinstance(values, (InferenceData, xr.Dataset)): + raise ValueError( + "InferenceData or xarray.Dateset object detected," + " use plot_posterior, plot_density or plot_pair" + " instead of plot_dist" + ) + if kind not in ["auto", "kde", "hist"]: raise TypeError('Invalid "kind":{}. Select from {{"auto","kde","hist"}}'.format(kind)) diff --git a/arviz/plots/posteriorplot.py b/arviz/plots/posteriorplot.py index 0d1139fd53..e7656e9dbe 100644 --- a/arviz/plots/posteriorplot.py +++ b/arviz/plots/posteriorplot.py @@ -22,7 +22,7 @@ def plot_posterior( coords=None, figsize=None, textsize=None, - credible_interval=None, + credible_interval="auto", multimodal=False, round_to: Optional[int] = None, point_estimate="auto", @@ -189,9 +189,9 @@ def plot_posterior( if coords is None: coords = {} - if credible_interval is None: + if credible_interval == "auto": credible_interval = rcParams["stats.credible_interval"] - else: + elif credible_interval is not None: if not 1 >= credible_interval > 0: raise ValueError("The value of credible_interval should be in the interval (0, 1]")