Skip to content

Instantly share code, notes, and snippets.

@mwaskom
Last active June 12, 2024 17:57
Show Gist options
  • Save mwaskom/de44147ed2974457ad6372750bbe5751 to your computer and use it in GitHub Desktop.
Save mwaskom/de44147ed2974457ad6372750bbe5751 to your computer and use it in GitHub Desktop.
A guide to replacing the deprecated `seaborn.distplot` function.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Humble-LiuAo
Copy link

Very helpful! thank you!

@Alaa-Saboukh02
Copy link

thank you , very helpful

@Teraces12
Copy link

Thanks a milion. It is really very convenient and helpful.

@richard-hurley
Copy link

Thank you straight-forward and easy to understand. Updated my code with relative ease!

@John-Sila
Copy link

Great. Thanks for this.

@the-heclop
Copy link

the-heclop commented Jun 16, 2023

getting unexpected keyword argument 'hist' when I try to disable histogram, when I am trying to just show density curve

ax1 = sns.displot(df['price'], hist=False, color="r", label="Actual Value")
sns.displot(Yhat, hist=False, color="b", label="Fitted Values" , ax=ax1)

1195 func = getattr(self, f"set_{k}", None)
1196 if not callable(func):
-> 1197 raise AttributeError(
1198 errfmt.format(cls=type(self), prop_name=k))
1199 ret.append(func(v))
1200 if ret:

AttributeError: Rectangle.set() got an unexpected keyword argument 'hist'

@TheCuriousCurator
Copy link

TheCuriousCurator commented Jul 27, 2023

not able to do multiple plots in a 2x2 grid using ax.

hisplot works but displot doesn't.

for i, ax in enumerate(axs.reshape(-1)):
    site = sites[i]
    sns.histplot(svi_mvn_samples[site], ax=ax, label="SVI (Multivariate Normal)", kde=True)
    sns.histplot(hmc_samples[site], ax=ax, label="HMC", kde=True)
    ax.set_title(site)

image

but when I the below code it doesnt plot in grid.

for i, ax in enumerate(axs.reshape(-1)):
    site = sites[i]
    sns.displot(svi_mvn_samples[site], ax=ax, label="SVI (Multivariate Normal)", kde=True)
    sns.displot(hmc_samples[site], ax=ax, label="HMC", kde=True)
    ax.set_title(site)

image

@bahramch487
Copy link

Hello,
thanks for your guidness.
I try your help untill in[12] but i get this message name 'df ' is not defined.
please help to solve this problem.
my python version is 3.11.

@bahramch487
Copy link

sns.histplot(df, x="flipper_length_mm", alpha=.4)
Traceback (most recent call last):
File "", line 1, in
NameError: name 'df' is not defined

@bahramch487
Copy link

distplot is a deprecated function and will be removed in seaborn v0.14.0.

Please adapt your code to use either displot (a figure-level function with
similar flexibility) or kdeplot (an axes-level function for kernel density plots).

@reachbharathan
Copy link

Thanks for such a detailed briefing, I am sure there would have been lots of thoughts and efforts in the change,
greatly appreciate @mwaskom . will check the latest version and provide feedbacks if any.

@kururu-abdo
Copy link

i got this error

ValueError: Multi-dimensional indexing (e.g. obj[:, None]) is no longer supported. Convert to a numpy array before indexing instead.

ax1 = sns.distplot(df['Salary'], hist=False, color="r", label="Actual Value")
sns.distplot(yhatRedge2, hist=False, color="b", label="Fitted Values" , ax=ax1)

@osman-haider
Copy link

i am facing error
ValueError: Multi-dimensional indexing (e.g. obj[:, None]) is no longer supported. Convert to a numpy array before indexing instead.

@bahramch487
Copy link

bahramch487 commented Sep 7, 2023 via email

@Chinaskidev
Copy link

ohhh my life so great!! thanks.

@swapnak1512
Copy link

Hi All,
I am facing below errors while using seaborn displot and hisplot:
Please help me in resolving the issue. Note: Same error with sns.histplot(tips["total_bill"])

Code:
import seaborn as sns
tips = sns.load_dataset('tips')
sns.displot(tips["total_bill"])

Errors
C:\Users\xxx\PycharmProjects\HelloWorld\venv\Lib\site-packages\seaborn_oldcore.py:1498: FutureWarning: is_categorical_dtype is deprecated and will be removed in a future version. Use isinstance(dtype, CategoricalDtype) instead
if pd.api.types.is_categorical_dtype(vector):
C:\Users\xxx\PycharmProjects\HelloWorld\venv\Lib\site-packages\seaborn_oldcore.py:1119: FutureWarning: use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.
with pd.option_context('mode.use_inf_as_na', True):

@zwitter689
Copy link

Really appreciate this, I imagine this takes a lot of work and the rewards are nebulous. Nonetheless, this is good stuff and your deserve kudos.

@BeUnstopable
Copy link

Hello, thanks for your guidness. I try your help untill in[12] but i get this message name 'df ' is not defined. please help to solve this problem. my python version is 3.11.

can your share your code to fix the error

@i80287
Copy link

i80287 commented Oct 19, 2023

How can I add normal distribution over histogram? Using distplot it is seaborn.distplot(series, fit=scipy.stats.norm). But none of hisplot and displot has the"fit" argument

@DavidAdonduwa
Copy link

Noted. Thanks

@JerryTsiba
Copy link

Thank you. That was useful.

@Owino-Kevin
Copy link

This is very helpful. Thank you.

@Nyantahi
Copy link

Nyantahi commented Jan 6, 2024

getting unexpected keyword argument 'hist' when I try to disable histogram, when I am trying to just show density curve

ax1 = sns.displot(df['price'], hist=False, color="r", label="Actual Value")
sns.displot(Yhat, hist=False, color="b", label="Fitted Values" , ax=ax1)

1195 func = getattr(self, f"set_{k}", None) 1196 if not callable(func): -> 1197 raise AttributeError( 1198 errfmt.format(cls=type(self), prop_name=k)) 1199 ret.append(func(v)) 1200 if ret:

AttributeError: Rectangle.set() got an unexpected keyword argument 'hist'

You have to use kind="kde" and remove hist="False" like the code below:

ax1 = sns.displot(df['price'], kind="kde", color="r", label="Actual Value")
sns.displot(Y_hat, color="b", kind="kde", label="Fitted Values", ax=ax1) 

@fanel27
Copy link

fanel27 commented Feb 18, 2024

Thank you for the explanations!

@eluseful
Copy link

eluseful commented Mar 4, 2024

Thanks, good stuff!

@Andres-Abi
Copy link

Thanks, is perfect

@Kushoza8
Copy link

Good Explaination

@vishwajeet-yaduraj
Copy link

cool, now I know what to do lol.

@abirmazumdar03
Copy link

Thank you sir...This notebook was a great help

@win7
Copy link

win7 commented Jun 12, 2024

Thanks, it was a great...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment