lets_plot.facet_grid

lets_plot.facet_grid(x=None, y=None, x_order=1, y_order=1, x_format=None, y_format=None)

Splits data by one or two faceting variables. For each data subset creates a plot panel and lays out panels as grid. The grid columns are defined by X faceting variable and rows are defined by Y faceting variable.

Parameters
  • x (str) – Variable name which defines columns of the facet grid.

  • y (str) – Variable name which defines rows of the facet grid.

  • x_order (int, default=1) – Specifies ordering direction of columns. 1 - ascending, -1 - descending.

  • y_order (int, default=1) – Specifies ordering direction of rows. 1 - ascending, -1 - descending.

  • x_format (str) – Specifies the format pattern for displaying faceting values in columns.

  • y_format (str) – Specifies the format pattern for displaying faceting values in rows.

Returns

Facet grid specification.

Return type

FeatureSpec

Note

Format pattern in the x_format / y_format parameters can be just a number format (like ‘d’) or a string template where number format is surrounded by curly braces: “{d} cylinders”.

For example:

  • ‘.2f’ -> ‘12.45’,

  • ‘Score: {.2f}’ -> ‘Score: 12.45’,

  • ‘Score: {}’ -> ‘Score: 12.454789’.

For more info see https://lets-plot.org/pages/formats.html.

Examples

1import numpy as np
2from lets_plot import *
3LetsPlot.setup_html()
4n = 100
5np.random.seed(42)
6x = np.random.normal(size=n)
7group = np.random.choice(['a', 'b'], size=n)
8ggplot({'x': x, 'group': group}, aes(x='x')) + \
9    geom_histogram() + facet_grid(x='group')