plotnine.facets.facet.facet

class plotnine.facets.facet.facet(scales: Literal['fixed', 'free', 'free_x', 'free_y'] = 'fixed', shrink: bool = True, labeller: Literal['label_value', 'label_both', 'label_context'] = 'label_value', as_table: bool = True, drop: bool = True, dir: Literal['h', 'v'] = 'h')[source]

Base class for all facets

Parameters
scalespython:str in ['fixed', 'free', 'free_x', 'free_y']

Whether x or y scales should be allowed (free) to vary according to the data along the rows or the columns. Default is 'fixed'.

shrinkbool

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

labellerpython:str | function

How to label the facets. If it is a str, it should be one of 'label_value' 'label_both' or 'label_context'. Default is 'label_value'

as_tablebool

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. Default it True.

dropbool

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. Default is True.

dirpython:str in ['h', 'v']

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

ncol: int

number of columns

nrow: int

number of rows

params: dict[str, Any]

A dict of parameters created depending on the data (Intended for extensions)

free: dict[Literal['x', 'y'], bool]

Which axis scales are free

set_properties(gg: Ggplot)[source]

Copy required properties from ggplot object

setup_data(data: list[pandas.core.frame.DataFrame]) list[pandas.core.frame.DataFrame][source]

Allow the facet to manipulate the data

Parameters
datapython:list of dataframes

Data for each of the layers

Returns
datapython:list of dataframes

Data for each of the layers

Notes

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

setup_params(data: list[pandas.core.frame.DataFrame])[source]

Create facet parameters

Parameters
datapython:list of dataframes

Plot data and data for the layers

map(data: DataFrame, layout: DataFrame) DataFrame[source]

Assign a data points to panels

Parameters
dataDataFrame

Data for a layer

layoutDataFrame

As returned by self.compute_layout

Returns
dataDataFrame

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

compute_layout(data: list[pandas.core.frame.DataFrame]) DataFrame[source]

Compute layout

Parameters
dataDataframes

Dataframe for a each layer

finish_data(data: pd.DataFrame, layout: Layout) pd.DataFrame[source]

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
dataDataFrame

A single layer's data.

layoutLayout

Layout

Returns
dataDataFrame

Modified layer data

train_position_scales(layout: Layout, layers: Layers) facet[source]

Compute ranges for the x and y scales

make_ax_strips(layout_info: layout_details, ax: Axes) Strips[source]

Create strips for the facet

Parameters
layout_infodict-like

Layout information. Row from the layout table

axaxes

Axes to label

set_limits_breaks_and_labels(panel_params: panel_view, ax: Axes)[source]

Add limits, breaks and labels to the axes

Parameters
rangesdict-like

range information for the axes

axAxes

Axes

make_axes(figure: Figure, layout: pd.DataFrame, coordinates: Coord) list[Axes][source]

Create and return Matplotlib axes