plotnine.facets.facet.facet

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

Parameters:
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(**kwargs)[source]

Set properties

setup_data(data)[source]

Allow the facet to manipulate the data

Parameters:
data : list of dataframes

Data for each of the layers

Returns:
data : 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)[source]

Create facet parameters

Parameters:
data : list of dataframes

Plot data and data for the layers

map(data, layout)[source]

Assign a data points to panels

Parameters:
data : DataFrame

Data for a layer

layout : DataFrame

As returned by self.compute_layout

Returns:
data : DataFrame

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

compute_layout(data)[source]

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.

Parameters:
data : DataFrame

Layer data.

layout : Layout

Layout

Returns:
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

spaceout_and_resize_panels()[source]

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

Parameters:
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

Returns:
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