hihik
hihik

Reputation: 3

Seaborn.Distplot produces a histogram and a KDE line with different x-axis - how are they merged in the plot?

Using this I'm pulling the plotted data from the Seaborn.Distplot. Surprisingly both histogram and KDE are returning different x-axis values. First, practical, question is how are these 2 x-axis combined in the same plot? Second, theoretical, question is why don't bins match - shouldn't both densities have been created with the same underlying bins?

Upvotes: 0

Views: 985

Answers (1)

mwaskom
mwaskom

Reputation: 49002

I'm not sure exactly what kind of answer you're looking for with the first question, but they are plotted independently, and nothing in matplotlib requires that two artists drawn on the same axes have identical x axis data.

To answer the second question, kernel density estimation doesn't use binning. Roughly speaking, it replaces each observation with a kernel, sums the kernels at each point in an evaluation grid, and normalizes. (Illustrated here). The histogram is also normalized to show a density, so you can plot one over top of the other and they will match. But there doesn't have to be any correspondence between the histogram bins and the evaluation grid for the KDE.

Upvotes: 1

Related Questions