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 4 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
17 changes: 14 additions & 3 deletions arviz/plots/backends/matplotlib/distplot.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Matplotlib distplot."""
import warnings
import matplotlib.pyplot as plt

import numpy as np
import xarray as xr
from . import backend_show
from ...kdeplot import plot_kde
from ...plot_utils import matplotlib_kwarg_dealiaser

from ....data import InferenceData

def plot_dist(
values,
Expand Down Expand Up @@ -87,12 +88,22 @@ def plot_dist(

def _histplot_mpl_op(values, values2, rotated, ax, hist_kwargs):
"""Add a histogram for the data to the axes."""
if isinstance(values, xr.Dataset):
raise ValueError(
"Cannot directly convert xarray.Dataset to numpy array."
" Instead, create an xarray.DataArray first "
"or Use plot_posterior, plot_density, plot_joint"
"or plot_pair instead of plot_dist"
)
if isinstance(values, InferenceData):
raise ValueError(" Inference Data object detected. Use plot_posterior instead of plot_dist")

OriolAbril marked this conversation as resolved.
Show resolved Hide resolved
if values2 is not None:
raise NotImplementedError("Insert hexbin plot here")

bins = hist_kwargs.pop("bins")
OriolAbril marked this conversation as resolved.
Show resolved Hide resolved
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
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