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 2 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
5 changes: 4 additions & 1 deletion arviz/plots/backends/matplotlib/distplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ 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 type(values).__name__ == "DataArray":
ax.hist(values.values.flatten(), bins=bins, **hist_kwargs)
else:
ax.hist(values, bins=bins, **hist_kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

Here I'd use only values = np.asarray(values).faltten() (and probably the same in bokeh file, haven't checked though). This will accept DataArrays stright away.

Moreover, it is probably a good idea to add some errors in the general file plots/distplot.py in a similar way to plot_kde, so users get some informative error if they try to use the function on an inference data or a dataset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this solution is also working fine.

For, the second suggestion, Are following error appropriate?

"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"
and
" Inference Data object detected. Use plot_posterior instead of plot_dist"


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