Neil Bartlett
Neil Bartlett

Reputation: 643

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?

Upvotes: 16

Views: 23991

Answers (3)

Scott
Scott

Reputation: 5848

Simply:

sns.histplot(your_data, kde=True)

Upvotes: 0

Juliane Foo
Juliane Foo

Reputation: 75

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

Upvotes: 4

Neil Bartlett
Neil Bartlett

Reputation: 643

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")

Upvotes: 36

Related Questions