class plotnine.stats.stat_function(mapping=None, data=None, **kwargs)[source]

Superimpose a function onto a plot


stat_function(mapping=None, data=None, geom='path', position='identity',
              na_rm=False, args=None, n=101, fun=None, xlim=None, **kwargs)

Only the mapping and data can be positional, the rest must be keyword arguments. **kwargs can be aesthetics (or parameters) used by the geom.

mappingaes, optional

Aesthetic mappings created with aes(). If specified and inherit.aes=True, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.


Default value



The bold aesthetics are required.

Options for computed aesthetics

'x'  # x points are which the function is evaluated
'y'  # Points evaluated at x
datadataframe, optional

The data to be displayed in this layer. If None, the data from from the ggplot() call is used. If specified, it overrides the data from the ggplot() call.

geomstr or geom, optional (default: geom_path)

The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.

positionstr or position, optional (default: position_identity)

Position adjustment. If it is a string, it must be registered and known to Plotnine.

na_rmbool, optional (default: False)

If False, removes missing values with a warning. If True silently removes missing values.


Function to evaluate.

nint, optional (default: 101)

Number of points at which to evaluate the function.

xlimtuple (default: None)

x limits for the range. The default depends on the x aesthetic. There is not an x aesthetic then the xlim must be provided.

argstuple or dict (default: None)

Arguments to pass to fun.