Skip to content
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
6 changes: 5 additions & 1 deletion pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,7 @@ def hist(
def kde(
self,
bw_method: Literal["scott", "silverman"] | float | Callable | None = None,
weights: np.ndarray | None = None,
ind: np.ndarray | int | None = None,
**kwargs,
) -> PlotAccessor:
Expand All @@ -1470,6 +1471,9 @@ def kde(
'scott', 'silverman', a scalar constant or a callable.
If None (default), 'scott' is used.
See :class:`scipy.stats.gaussian_kde` for more information.
weights : NumPy array, optional
Weights of datapoints. This must be the same shape as dataset.
If None (default), the samples are assumed to be equally weighted.
ind : NumPy array or int, optional
Evaluation points for the estimated PDF. If None (default),
1000 equally spaced points are used. If `ind` is a NumPy array, the
Expand Down Expand Up @@ -1560,7 +1564,7 @@ def kde(

>>> ax = df.plot.kde(ind=[1, 2, 3, 4, 5, 6])
"""
return self(kind="kde", bw_method=bw_method, ind=ind, **kwargs)
return self(kind="kde", bw_method=bw_method, weights=weights, ind=ind, **kwargs)

density = kde

Expand Down
3 changes: 2 additions & 1 deletion pandas/plotting/_matplotlib/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def _plot( # type: ignore[override]
y: np.ndarray,
style=None,
bw_method=None,
weights=None,
ind=None,
column_num=None,
stacking_id: int | None = None,
Expand All @@ -277,7 +278,7 @@ def _plot( # type: ignore[override]
from scipy.stats import gaussian_kde

y = remove_na_arraylike(y)
gkde = gaussian_kde(y, bw_method=bw_method)
gkde = gaussian_kde(y, bw_method=bw_method, weights=weights)

y = gkde.evaluate(ind)
lines = MPLPlot._plot(ax, ind, y, style=style, **kwds)
Expand Down