Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use kde_kws parameters for seaborn.histplot()?

Tags:

seaborn

I am trying to use sns.histplot() instead of sns.distplot() since I got the following message in colab:

FutureWarning: distplot is a deprecated function and will be removed in a future version. Please adapt your code to use either displot (a figure-level function with similar flexibility) or histplot (an axes-level function for histograms).

Code:

import pandas as pd
import seaborn as sns

df = sns.load_dataset('tips')
sns.histplot(df['tip'], kde=True, kde_kws={'fill' : True});

I got an error when passing kde_kws parameters inside sns.histplot():

TypeError: init() got an unexpected keyword argument 'fill'

like image 416
deal2k Avatar asked Nov 04 '25 03:11

deal2k


1 Answers

From the documentation kde_kws= is intended to pass arguments "that control the KDE computation, as in kdeplot()." It is not entirely explicit which arguments those are, but they seem to be the ones like bw_method= and bw_adjust= that change the way the KDE is computed, rather than displayed. If you want to change the appearance of the KDE plot, the you can use line_kws=, but, as the name implies, the KDE is represented only by a line and therefore cannot be filled.

If you want both a histogram and a filled KDE, you need to combine histplot() and kdeplot() on the same axes

sns.histplot(df['tip'], stat='density')
sns.kdeplot(df['tip'], fill=True)
like image 182
Diziet Asahi Avatar answered Nov 06 '25 04:11

Diziet Asahi