T_T
T_T

Reputation: 1290

StatsModels in Python: What is measured on the horizontal axis?

I run the following Python code to generate the attached figure of Kernel density with the horizontal axis from 0 to 500. Given that the code generates 100 observations between -2.157 and 2.830, I would expect the horizontal axis shows values like between -3 and 3. What is actually measured on the horizon taxis?

import numpy as np
import statsmodels.api as sm
import matplotlib.pyplot as plt

np.random.seed(1234567)
k = np.random.normal(0, 1, 100)
dens = sm.nonparametric.KDEUnivariate(k)
dens.fit()
plt.plot(dens.density)

enter image description here

Thanks for your help in advance.

Upvotes: 0

Views: 92

Answers (1)

T_T
T_T

Reputation: 1290

Replacing

plt.plot(dens.density)

with

plt.plot(dens.support, dens.density)

gives the following result I expected.

enter image description here

Upvotes: 1

Related Questions