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
scalesstr 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'.

shrinkbool

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

labellerstr | 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.

dirstr 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(self, **kwargs)[source]

Set properties

setup_data(self, data)[source]

Allow the facet to manipulate the data

Parameters
datalist of dataframes

Data for each of the layers

Returns
datalist 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(self, data)[source]

Create facet parameters

Parameters
datalist of dataframes

Plot data and data for the layers

map(self, data, layout)[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(self, data)[source]

Compute layout

finish_data(self, 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
dataDataFrame

Layer data.

layoutLayout

Layout

Returns
dataDataFrame

Modified layer data

train_position_scales(self, layout, layers)[source]

Compute ranges for the x and y scales

make_axes(self, figure, layout, coordinates)[source]

Create and return Matplotlib axes

spaceout_and_resize_panels(self)[source]

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

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

Breadth of the strip background in inches

Parameters
locationstr in ['top', 'right']

Location of the strip text

num_linesint

Number of text lines

strip_dimensions(self, text_lines, location, ax)[source]

Calculate the dimension

Returns
outtypes.SimpleNamespace

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

draw_strip_text(self, text_lines, location, ax)[source]

Create a background patch and put a label on it