import pandas as pd
import seaborn as sns
ser_test = pd.Series([1,0,1,4,6,0,6,5,1,3,2,5,1])
sns.kdeplot(ser_test, cumulative=True)
The above code g
if you don't want to wait for the seaborn git update to get released in a stable version, you can try one of the solutions in the issue page. specifically henrymartin1's suggestion to try manually passing in a small bandwidth inside a try/catch block (suggested by ahartikainen) which grabs the text of this specific error (so other errors still get raised):
try:
sns.distplot(df)
except RuntimeError as re:
if str(re).startswith("Selected KDE bandwidth is 0. Cannot estimate density."):
sns.distplot(df, kde_kws={'bw': 0.1})
else:
raise re
This worked for me.
sns.distplot(ser_test, hist = False, rug = True, rug_kws = {'color' : 'r'})
sns.distplot(ser_test, hist = False, rug = True, rug_kws = {'color' : 'r'}, kde_kws = {'bw' : 1})
sns.distplot(ser_test, hist = False, rug = True, rug_kws = {'color' : 'r'}, kde_kws = {'bw' : 1.5, 'kernel' : 'tri'})
pip uninstall statsmodels
solved a similar problem with the same error.
What's going on here is that Seaborn (or rather, the library it relies on to calculate the KDE - scipy or statsmodels) isn't managing to figure out the "bandwidth", a scaling parameter used in the calculation. You can pass it manually. I played with a few values and found 1.5 gave a graph at the same scale as your previous:
sns.kdeplot(ser_test, cumulative=True, bw=1.5)
See also here. Worth installing statsmodels
if you don't have it.
The problem occurs because of statsmodels.
Anyway, to solve the issue for seaborn version starting from 0.10.0, just place diag_kws={'bw': 1} as arg.
Try to figure out the optimal value for bandwidth.