KDE (kernel density estimation)#
A KDE plot shows the estimated probability density of a numeric variable.
Requires scipy (pip install gufo[scipy]).
Standalone density plot#
gufo.chart(df).kdeplot("x").show()
Filled density#
gufo.chart(df).kdeplot("x", fill=True).show()
Grouped by category#
gufo.chart(df).kdeplot("x", color="category").show()
Histogram overlay#
Pass a gufo.kde() config to the kde parameter of .histogram() to
overlay a density curve on top of the histogram. The curve is automatically
scaled to match the histogram’s y-axis.
gufo.chart(df).histogram("income", kde=gufo.kde()).show()
# Filled overlay
gufo.chart(df).histogram("income", kde=gufo.kde(fill=True, alpha=0.3)).show()
Bandwidth#
The bw_method parameter is passed to scipy.stats.gaussian_kde.
gufo.chart(df).kdeplot("x", bw_method=0.3).show()
Matplotlib passthrough#
Extra keyword arguments are forwarded to the underlying axes.plot() or
axes.fill_between() call.
gufo.chart(df).kdeplot("x", zorder=5, dash_capstyle="round").show()
API reference#
See gufo.kde(), gufo.stats.kde.KDE,
and gufo.core.chart.Chart.kdeplot().