Stats#

Statistical overlay configuration classes and their factory functions.

Factory functions#

gufo.regression(degree=1, *, color=None, linestyle='-', linewidth=2.0, label=None, n_points=200)[source]#

Create a regression fit configuration for scatter plots.

gufo.kde(*, bw_method=None, color=None, linestyle='-', linewidth=2.0, alpha=1.0, label=None, fill=False, n_points=200)[source]#

Create a KDE configuration for density plots.

gufo.lowess(frac=0.6667, *, color=None, linestyle='-', linewidth=2.0, label=None)[source]#

Create a LOWESS smoothing configuration for scatter plots.

Requires statsmodels. Install with: pip install gufo[stats].

Config classes#

class gufo.stats.regression.Regression(degree=1, color=None, linestyle='-', linewidth=2.0, label=None, n_points=200)[source]#

Bases: object

Configuration for a regression fit line overlaid on a scatter plot.

Users create instances via gufo.regression(), never directly.

Parameters:
  • degree (int)

  • color (str | None)

  • linestyle (str)

  • linewidth (float)

  • label (str | None)

  • n_points (int)

degree: int = 1#
color: str | None = None#
linestyle: str = '-'#
linewidth: float = 2.0#
label: str | None = None#
n_points: int = 200#
render(x, y, axes)[source]#

Fit and draw the regression line on the given axes.

Parameters#

x : numpy array — already resolved via DataAdapter. y : numpy array — already resolved via DataAdapter. axes : matplotlib Axes.

__init__(degree=1, color=None, linestyle='-', linewidth=2.0, label=None, n_points=200)#
Parameters:
  • degree (int)

  • color (str | None)

  • linestyle (str)

  • linewidth (float)

  • label (str | None)

  • n_points (int)

Return type:

None

class gufo.stats.kde.KDE(bw_method=None, color=None, linestyle='-', linewidth=2.0, alpha=1.0, label=None, fill=False, n_points=200)[source]#

Bases: object

Configuration for a KDE curve.

Used as an overlay on .histogram() via histogram(kde=gufo.kde(…)). For a standalone density plot, use Chart.kdeplot() instead.

Users create instances via gufo.kde(), never directly.

Parameters:
bw_method: object | None = None#
color: str | None = None#
linestyle: str = '-'#
linewidth: float = 2.0#
alpha: float = 1.0#
label: str | None = None#
fill: bool = False#
n_points: int = 200#
render(x, axes, *, scale_to_hist=False, hist_patches=None, **extra_kwargs)[source]#

Compute and draw the KDE curve.

Parameters#

xnumpy array

The data to estimate density for.

axesmatplotlib Axes

Target axes to draw on.

scale_to_histbool

If True, scale the KDE to match histogram bar heights.

hist_patcheslist or None

Patches from axes.hist(), used for bin width when scaling.

**extra_kwargs

Additional keyword arguments passed through to matplotlib.

__init__(bw_method=None, color=None, linestyle='-', linewidth=2.0, alpha=1.0, label=None, fill=False, n_points=200)#
Parameters:
Return type:

None

class gufo.stats.lowess.Lowess(frac=0.6667, color=None, linestyle='-', linewidth=2.0, label=None)[source]#

Bases: object

Configuration for a LOWESS smoothing curve overlaid on a scatter plot.

Users create instances via gufo.lowess(), never directly.

Parameters:
frac: float = 0.6667#
color: str | None = None#
linestyle: str = '-'#
linewidth: float = 2.0#
label: str | None = None#
render(x, y, axes)[source]#

Fit and draw the LOWESS curve on the given axes.

Parameters#

x : numpy array — already resolved via DataAdapter. y : numpy array — already resolved via DataAdapter. axes : matplotlib Axes.

__init__(frac=0.6667, color=None, linestyle='-', linewidth=2.0, label=None)#
Parameters:
Return type:

None