plotnine.facets.facet.facet

facet(
    scales="fixed",
    shrink=True,
    labeller="label_value",
    as_table=True,
    drop=True,
    dir="h"
)

Base class for all facets

Parameters

scales : Literal["fixed", "free", "free_x", "free_y"] = "fixed"

Whether x or y scales should be allowed (free) to vary according to the data on each of the panel.

shrink : bool = True

Whether to shrink the scales to the output of the statistics instead of the raw data. Default is True.

labeller : CanBeStripLabellingFunc = "label_value"

How to label the facets. A string value if it should be one of ["label_value", "label_both", "label_context"].

as_table : bool = True

If True, the facets are laid out like a table with the highest values at the bottom-right. If False the facets are laid out like a plot with the highest value a the top-right

drop : bool = True

If True, all factor levels not used in the data will automatically be dropped. If False, all factor levels will be shown, regardless of whether or not they appear in the data.

dir : Literal["h", "v"] = "h"

Direction in which to layout the panels. h for horizontal and v for vertical.

Methods

Name Description
compute_layout Compute layout
finish_data Modify data before it is drawn out by the geom
make_figure Create and return Matplotlib figure and subplot axes
make_strips Create strips for the facet
map Assign a data points to panels
set_limits_breaks_and_labels Add limits, breaks and labels to the axes
setup_data Allow the facet to manipulate the data
setup_params Create facet parameters
train_position_scales Compute ranges for the x and y scales

compute_layout

compute_layout(data)

Compute layout

Parameters

data : list[pd.DataFrame]

Dataframe for a each layer

finish_data

finish_data(data, layout)

Modify data before it is drawn out by the geom

The default is to return the data without modification. Subclasses should override this method as the require.

Parameters

data : pd.DataFrame

A single layer’s data.

layout : Layout

Layout

Returns

pd.DataFrame

Modified layer data

make_figure

make_figure()

Create and return Matplotlib figure and subplot axes

make_strips

make_strips(layout_info, ax)

Create strips for the facet

Parameters

layout_info : layout_details

Layout information. Row from the layout table

ax : Axes

Axes to label

map

map(data, layout)

Assign a data points to panels

Parameters

data : pd.DataFrame

Data for a layer

layout : pd.DataFrame

As returned by self.compute_layout

Returns

pd.DataFrame

Data with all points mapped to the panels on which they will be plotted.

set_limits_breaks_and_labels

set_limits_breaks_and_labels(panel_params, ax)

Add limits, breaks and labels to the axes

Parameters

panel_params : panel_view

range information for the axes

ax : Axes

Axes

setup_data

setup_data(data)

Allow the facet to manipulate the data

Parameters

data : list[pd.DataFrame]

Data for each of the layers

Returns

list[pd.DataFrame]

Data for each of the layers

Notes

This method will be called after setup_params, therefore the params property will be set.

setup_params

setup_params(data)

Create facet parameters

Parameters

data : list[pd.DataFrame]

Plot data and data for the layers

train_position_scales

train_position_scales(layout, layers)

Compute ranges for the x and y scales