Skip to content

Commit

Permalink
add warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aloctavodia committed Sep 16, 2024
1 parent 5aaa74b commit 969c335
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions arviz/plots/backends/matplotlib/kdeplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Matplotlib kdeplot."""
import warnings

import numpy as np
from matplotlib import pyplot as plt
Expand Down Expand Up @@ -153,6 +154,7 @@ 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 @@ -163,6 +165,11 @@ 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:
Expand Down
2 changes: 1 addition & 1 deletion arviz/plots/kdeplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def plot_kde(
>>> az.plot_kde(
... mu_posterior, values2=tau_posterior,
... contour_kwargs={"levels":3}, contourf_kwargs={"levels":3}
... contourf_kwargs={"levels":3}
... );
Plot 2d contour KDE with 30%, 60% and 90% HDI contours.
Expand Down

0 comments on commit 969c335

Please sign in to comment.