Search code examples
pythonseaborn

Updating Seaborn distplot code to version 0.11


Using distplot to plot a histogram

sns.distplot(a, color="red", label="100% Equities")

and running this under Seaborn version 0.11 or greater produces the following warning:

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). warnings.warn(msg, FutureWarning)

Using displot as a direct replacement (simply changing the function name from distplot to displot) does not produce the same histogram.

What is the replacement code?


Solution

  • Use

    • histplot instead of distplot
    • and add the keyword args kde=True, stat="density", linewidth=0

    So:

    sns.histplot(a, color="red", label="100% Equities", kde=True, stat="density", linewidth=0)
    

    replaces

    sns.distplot(a, color="red", label="100% Equities")