Minimal call
import random
rng = random.Random(10)
df1 = {"x": [rng.gauss(0, 1) for _ in range(300)]}
df2 = {"x": [rng.gauss(1.2, 1.3) for _ in range(300)]}
c = pt.chart(xlabel="value", ylabel="density")
c.add_density_1d(df1, aes(x="x"), fill=True)
c.add_density_1d(df2, aes(x="x"), fill=True)
Docstring
1-D Gaussian KDE curve — the bin-free alternative to histogram.
Where `hist` answers "how many in each bin?", `density_1d` answers
"what's the smoothed distribution shape?" — bin-free, scaled so the
area integrates to 1 so you can overlay multiple groups fairly.
c.add_density_1d(aes(x="col")) # columns via aes
c.add_density_1d(aes(x="col", color="group")) # one curve per group
Aesthetics:
color= bare → literal line color; aes(color="col") → grouped curves
fill=False True shades the area under each curve in the line color
palette= maps group levels → colors when color is mapped in aes
Other styling kwargs:
bw=None bandwidth override; defaults to Silverman's rule
n_grid=200 KDE evaluation grid resolution
alpha=0.25 fill opacity (used only when fill=True)
linewidth=1.6 curve stroke width
label=None legend label (single-series only)