When I tested functions of Scipy, a chart resulted by kernel density estimation caughtmy eyes. I felt that I saw it before. That’s a elephant digested by a boa constrictor…. or a hat.

Although KDE is opposite to the tale of The Little Prince, The mechanism is similar. The KDE makes smooth line along with density. That’s like a covering on a figure inside.

Also I made 3D physics version of covering chart in the previous post(Data-Viz Idea: 3D Membrane chart). If there is an elephant inside, the scene may become 3D version of The Little Prince.

So, Is the part of the book about KDE?

Probably not. But I can modify the original sentences as I prefer:

“My drawing was not a picture of a boa constrictor digesting an elephant. It was a picture of Python’s Kernel density estimation covering an bar chart. But since the literature men were not able to understand it, I made another drawing: I drew the inside of chart, so that the literature men could see it clearly. They always need to have things explained”.

## The code:

import numpy as np from scipy import stats from matplotlib.pylab import plt # Kernel density estimation: x = np.array([-5,-5,-5,-4,-3,-3,-2,-1,0,1,1,2,2,3]) kde1 = stats.gaussian_kde(x,"scott") x2 = np.linspace(-7,6, 50) fig = plt.figure() ax1 = fig.add_subplot(2,1,1) ax2 = fig.add_subplot(2,1,2) ax1.plot(x2,kde1(x2)*30) ax2.hist(x, bins=np.arange(-7,6)) ax2.plot(x2,kde1(x2)*30)