Updating Seaborn distplot code to version 0.11
Asked Answered
F

3

16

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?

Flatus answered 30/1, 2021 at 21:17 Comment(2)
label doesn't seem to be a parameter of displot: seaborn.pydata.org/generated/seaborn.displot.htmlIzmir
The code above is for distplot (not displot). distplot is the deprecated code and it does have a label. Also histplot (see the answer below) does inherit label from bar. If you chase down through the kwargs in the link you have given (select histplot, then at the end select bar -- you will find the label keyword is available.) Matplotlib does a lot of inheriting :-)Flatus
F
36

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")
Flatus answered 30/1, 2021 at 21:20 Comment(0)
B
4

Example of Code for Hisplot to show the frequency of first state and zero state of the machine at each point:

feature2_ok = df.loc[df["target"] == 1]

feature2_ng = df.loc[df["target"] == 0]

fig, ax = plt.subplots(figsize=(20, 6))
sns.histplot(feature2_ok["feature_2"], color="orange", label="100% Equities", kde=True, linewidth=0)

sns.histplot(feature2_ng["feature_2"], label="100% Equities", kde=True, linewidth=0)

ax.set(xlim=(-100, 700), 
 xticks=[-100, -50, 0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700])

plt.legend(["Frist State", "Zero State"])

plt.title('Machine Performance Feature 2')

plt.ylabel('Frequency')

plt.grid()

plt.show()

Output

Boat answered 6/10, 2021 at 13:50 Comment(0)
M
0

Simply:

sns.histplot(your_data, kde=True)
Maressa answered 27/12, 2023 at 4:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.