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

Fix credible_interval=None and plot_dist with ndim>2 #1115

Merged
merged 9 commits into from
Mar 15, 2020
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion arviz/plots/backends/bokeh/distplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should move this before using values for bins and do values = np.asarray(values).flatten() to use always flattened array.

if hist_kwargs.pop("cumulative", False):
hist = np.cumsum(hist)
hist /= hist[-1]
Expand Down
7 changes: 5 additions & 2 deletions arviz/plots/backends/matplotlib/distplot.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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")
OriolAbril marked this conversation as resolved.
Show resolved Hide resolved
if bins is None:
bins = get_bins(values)
ax.hist(np.asarray(values).flatten(), bins=bins, **hist_kwargs)
OriolAbril marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above


ax.hist(values, bins=bins, **hist_kwargs)
if rotated:
ax.set_yticks(bins[:-1])
else:
Expand Down
9 changes: 9 additions & 0 deletions arviz/plots/distplot.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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))

Expand Down
6 changes: 3 additions & 3 deletions arviz/plots/posteriorplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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]")

Expand Down