class plotnine.facets.facet.facet(scales='fixed', shrink=True, labeller='label_value', as_table=True, drop=True, dir='h')[source]

Base class for all facets

scales : str in ['fixed', 'free', 'free_x', 'free_y']

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

shrink : bool

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

labeller : 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_table : bool

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.

drop : bool

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.

dir : str in ``['h', 'v']

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

ncol = None

number of columns

nrow = None

number of rows

params = None

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

free = {'x': True, 'y': True}

Which axis scales are free


Set properties


Allow the facet to manipulate the data

data : list of dataframes

Data for each of the layers

data : list of dataframes

Data for each of the layers


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


Create facet parameters

data : list of dataframes

Plot data and data for the layers

map(data, layout)[source]

Assign a data points to panels

data : DataFrame

Data for a layer

layout : DataFrame

As returned by self.compute_layout

data : DataFrame

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


Compute layout

finish_data(data, layout)[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.

data : DataFrame

Layer data.

layout : Layout


data : DataFrame

Modified layer data

train_position_scales(layout, layers)[source]

Compute ranges for the x and y scales

make_axes(figure, layout, coordinates)[source]

Create and return Matplotlib axes


Adjust the spacing between the panels and resize them to meet the aspect ratio

strip_size(location='top', num_lines=None)[source]

Breadth of the strip background in inches

location : str in ['top', 'right']

Location of the strip text

num_lines : int

Number of text lines

strip_dimensions(text_lines, location, pid)[source]

Calculate the dimension

out : types.SimpleNamespace

A structure with all the coordinates required to draw the strip text and the background box.

draw_strip_text(text_lines, location, pid)[source]

Create a background patch and put a label on it