0

I am trying to obtain the pdf of a histogram using seaborn library, but the pdf returned has non zero probabilites for zero valued bins.

For example:

array = np.arange(20)
reversed_arr = array[::-1]

fig, axs = plt.subplots(1, 1, figsize=(30, 10))

ax1 = sns.distplot(reversed_arr, ax=axs, label='my hist')

fit1 = ax1.get_lines()[0].get_data()  

xfit1, yfit1 = fit1[0], fit1[1]
ax1.legend()

axs.plot(xfit1, yfit1, label='my pdf')
axs.set_ylim(ax1.get_ylim())

plt.legend()
plt.show()

This is what I get: histogram and its pdf of an array with descending values

As you can see, before zero (and after 18) on the x-axis, there are no values, yet positive probabilities.

Any help?

Community
  • 1
  • 1
YaserM
  • 185
  • 2
  • 9
  • Well, you're plotting a Gaussian approximation which supposes a smooth continuous underlying distribution. The kde isn't the pdf. – JohanC May 25 '20 at 08:38
  • is there a way to limit the interval of the kde? for example above would be from 0 to 18 – YaserM May 25 '20 at 08:56

0 Answers0