class plotnine.stats.stat_bin(mapping: Aes | None = None, data: DataLike | None = None, **kwargs: Any)[source]

Count cases in each interval


stat_bin(mapping=None, data=None, geom='histogram', position='stack',
         na_rm=False, binwidth=None, pad=False, breaks=None, bins=None,
         center=None, closed='right', boundary=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

'count'    # number of points in bin
'density'  # density of points in bin, scaled to integrate to 1
'ncount'   # count, scaled to maximum of 1
'ndensity' # density, scaled to maximum of 1
'ngroup'   # number of points in group
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_histogram)

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_stack)

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.

binwidthfloat, optional (default: None)

The width of the bins. The default is to use bins bins that cover the range of the data. You should always override this value, exploring multiple widths to find the best to illustrate the stories in your data.

binsint, optional (default: None)

Number of bins. Overridden by binwidth. If None, a number is computed using the freedman-diaconis method.

breaksarray-like, optional (default: None)

Bin boundaries. This supercedes the binwidth, bins, center and boundary.

centerfloat, optional (default: None)

The center of one of the bins. Note that if center is above or below the range of the data, things will be shifted by an appropriate number of widths. To center on integers, for example, use width=1 and center=0, even if 0 i s outside the range of the data. At most one of center and boundary may be specified.

boundaryfloat, optional (default: None)

A boundary between two bins. As with center, things are shifted when boundary is outside the range of the data. For example, to center on integers, use width=1 and boundary=0.5, even if 1 is outside the range of the data. At most one of center and boundary may be specified.

closedstr, optional (default: right)

Which edge of the bins is included, left or right.

padbool, optional (default: False)

If True, adds empty bins at either side of x. This ensures that frequency polygons touch 0.