plotnine.facets.facet_grid

class plotnine.facets.facet_grid(facets: str | tuple[str | list[str], str | list[str]], margins: bool | list[str] = False, scales: Literal['fixed', 'free', 'free_x', 'free_y'] = 'fixed', space: Literal['fixed', 'free', 'free_x', 'free_y'] | dict[Literal['x', 'y'], list[int]] = 'fixed', shrink: bool = True, labeller: Literal['label_value', 'label_both', 'label_context'] = 'label_value', as_table: bool = True, drop: bool = True)[source]

Wrap 1D Panels onto 2D surface

Parameters
facetspython:str | python:tuple | python:list

A formula with the rows (of the tabular display) on the LHS and the columns (of the tabular display) on the RHS; the dot in the formula is used to indicate there should be no faceting on this dimension (either row or column). If a tuple/list is used, it must of size two, the elements of which must be strings or lists. If string formula is not processed as you may expect, use tuple/list. For example, the follow two specifications are equivalent:

'func(var4) ~ func(var1+var3) + func(var2)'
['func(var4)', ('func(var1+var3)', 'func(var2)')]

There may be cases where you cannot use a use a pure string formula, e.g.:

['var4', ('var1+var3', 'var2')]
marginsbool | python:list[python:str]

variable names to compute margins for. True will compute all possible margins.

spacepython:str | python:dict

Control the size of the x or y sides of the panels. The size also depends to the scales parameter.

If a string, it should be one of ['fixed', 'free', 'free_x', 'free_y']. Currently, only the 'fixed' option is supported.

Alternatively if a dict, it indicates the relative facet size ratios such as:

{'x': [1, 2], 'y': [3, 1, 1]}

This means that in the horizontal direction, the second panel will be twice the length of the first. In the vertical direction the top facet will be the 3 times longer then the second and third facets.

Note that the number of dimensions in the list must equal the number of facets that will be produced.

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.