Skip to content

Commit

Permalink
use get_bins function to compute bins for density and posterior plot (#…
Browse files Browse the repository at this point in the history
…1049)

* used get_bins function to compute bins

* fix density plot bug

* run black

* update changelog
  • Loading branch information
agustinaarroyuelo authored Feb 6, 2020
1 parent a82ae30 commit ecc8468
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@


### Maintenance and fixes
* Fixed bug in density and posterior plot bin computation (#1049)
* Fixed bug in density plot ax argument (#1049)
* Fixed bug in extracting prior samples for cmdstanpy (#979)
* Fix erroneous warning in traceplot (#989)
* Correct bfmi denominator (#991)
Expand Down
3 changes: 2 additions & 1 deletion arviz/plots/backends/bokeh/densityplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
_create_axes_grid,
calculate_point_estimate,
_fast_kde,
get_bins,
)
from ....stats import hpd
from ....stats.stats_utils import histogram
Expand Down Expand Up @@ -159,7 +160,7 @@ def _d_helper(

else:
xmin, xmax = hpd(vec, credible_interval, multimodal=False)
bins = range(xmin, xmax + 2)
bins = get_bins(vec)

_, hist, edges = histogram(vec, bins=bins)

Expand Down
5 changes: 2 additions & 3 deletions arviz/plots/backends/bokeh/posteriorplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
format_sig_figs,
round_num,
calculate_point_estimate,
get_bins,
)
from ....stats import hpd

Expand Down Expand Up @@ -245,9 +246,7 @@ def format_axes():
else:
if bins is None:
if values.dtype.kind == "i":
xmin = values.min()
xmax = values.max()
bins = range(xmin, xmax + 2)
bins = get_bins(values)
else:
bins = "auto"
kwargs.setdefault("align", "left")
Expand Down
27 changes: 16 additions & 11 deletions arviz/plots/backends/matplotlib/densityplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
_create_axes_grid,
calculate_point_estimate,
_fast_kde,
get_bins,
)


Expand Down Expand Up @@ -37,16 +38,20 @@ def plot_density(
show,
):
"""Matplotlib densityplot."""
_, ax = _create_axes_grid(
length_plotters,
rows,
cols,
figsize=figsize,
squeeze=False,
backend="matplotlib",
backend_kwargs=backend_kwargs,
)
axis_map = {label: ax_ for label, ax_ in zip(all_labels, ax.flatten())}
if ax is None:
_, ax = _create_axes_grid(
length_plotters,
rows,
cols,
figsize=figsize,
squeeze=False,
backend="matplotlib",
backend_kwargs=backend_kwargs,
)
else:
ax = np.atleast_2d(ax)

axis_map = {label: ax_ for label, ax_ in zip(all_labels, np.ravel(ax))}

for m_idx, plotters in enumerate(to_plot):
for var_name, selection, values in plotters:
Expand Down Expand Up @@ -150,7 +155,7 @@ def _d_helper(

else:
xmin, xmax = hpd(vec, credible_interval, multimodal=False)
bins = range(xmin, xmax + 2)
bins = get_bins(vec)
if outline:
ax.hist(vec, bins=bins, color=color, histtype="step", align="left")
if shade:
Expand Down
3 changes: 2 additions & 1 deletion arviz/plots/backends/matplotlib/posteriorplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
format_sig_figs,
round_num,
calculate_point_estimate,
get_bins,
)


Expand Down Expand Up @@ -258,7 +259,7 @@ def format_axes():
if values.dtype.kind == "i":
xmin = values.min()
xmax = values.max()
bins = range(xmin, xmax + 2)
bins = get_bins(values)
ax.set_xlim(xmin - 0.5, xmax + 0.5)
else:
bins = "auto"
Expand Down

0 comments on commit ecc8468

Please sign in to comment.