Skip to content

Commit

Permalink
make hdi_probs default
Browse files Browse the repository at this point in the history
  • Loading branch information
aloctavodia committed Sep 19, 2024
1 parent 969c335 commit 6968a86
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
9 changes: 0 additions & 9 deletions arviz/plots/backends/matplotlib/kdeplot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Matplotlib kdeplot."""
import warnings

import numpy as np
from matplotlib import pyplot as plt
from matplotlib import _pylab_helpers
Expand Down Expand Up @@ -154,7 +152,6 @@ def plot_kde(
else:
contour_kwargs = matplotlib_kwarg_dealiaser(contour_kwargs, "contour")
contour_kwargs.setdefault("colors", "0.5")
contour_kwargs.setdefault("levels", None)
contourf_kwargs = matplotlib_kwarg_dealiaser(contourf_kwargs, "contour")
pcolormesh_kwargs = matplotlib_kwarg_dealiaser(pcolormesh_kwargs, "pcolormesh")
pcolormesh_kwargs.setdefault("shading", "auto")
Expand All @@ -165,12 +162,6 @@ def plot_kde(
ax.grid(False)
if contour:
qcfs = ax.contourf(x_x, y_y, density, antialiased=True, **contourf_kwargs)
if isinstance(contour_kwargs["levels"], int):
warnings.warn(
"Ignoring contour_kwargs['levels'] use contourf_kwargs['levels'] instead",
UserWarning,
)
contour_kwargs["levels"] = qcfs.levels[1:]
ax.contour(x_x, y_y, density, **contour_kwargs)
if not fill_last:
alpha = np.ones(len(qcfs.allsegs), dtype=float)
Expand Down
13 changes: 9 additions & 4 deletions arviz/plots/kdeplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def plot_kde(
quantiles=None,
rotated=False,
contour=True,
hdi_probs=None,
hdi_probs=[0.5, 0.8, 0.94],
fill_last=False,
figsize=None,
textsize=None,
Expand Down Expand Up @@ -72,7 +72,7 @@ def plot_kde(
If True plot the 2D KDE using contours, otherwise plot a smooth 2D KDE.
hdi_probs : list, optional
Plots highest density credibility regions for the provided probabilities for a 2D KDE.
Defaults to matplotlib chosen levels with no fixed probability associated.
Defaults to [0.5, 0.8, 0.94].
fill_last : bool, default False
If True fill the last contour of the 2D KDE plot.
figsize : (float, float), optional
Expand Down Expand Up @@ -226,7 +226,7 @@ def plot_kde(
>>> az.plot_kde(
... mu_posterior, values2=tau_posterior,
... contourf_kwargs={"levels":3}
... contour_kwargs={"levels":3}, contourf_kwargs={"levels":3}
... );
Plot 2d contour KDE with 30%, 60% and 90% HDI contours.
Expand Down Expand Up @@ -279,6 +279,7 @@ def plot_kde(
contour_levels = _find_hdi_contours(density, hdi_probs)
contour_levels.sort()


contour_level_list = [0] + list(contour_levels) + [density.max()]

# Add keyword arguments to contour, contourf
Expand All @@ -289,7 +290,11 @@ def plot_kde(
"Using 'hdi_probs' in favor of 'levels'.",
UserWarning,
)
contour_kwargs["levels"] = contour_level_list

if backend == "bokeh":
contour_kwargs["levels"] = contour_level_list
elif backend == "matplotlib":
contour_kwargs["levels"] = contour_level_list[1:]

contourf_kwargs = _init_kwargs_dict(contourf_kwargs)
if "levels" in contourf_kwargs:
Expand Down

0 comments on commit 6968a86

Please sign in to comment.