gggrid#
- gggrid(plots: list, ncol: int | None = None, *, sharex: str | None = None, sharey: str | None = None, widths: list | None = None, heights: list | None = None, hspace: float | None = None, vspace: float | None = None, fit: bool | None = None, align: bool | None = None, guides: str | None = None) SupPlotsSpec#
Combine several plots on one figure, organized in a regular grid.
- Parameters:
- plotslist
A list where each element is a plot specification, a subplot specification, or None. Use None to fill in empty cells in the grid.
- ncolint
Number of columns in the grid. If not specified, shows plots horizontally, in one row.
- sharex, shareybool or str, default=False
Controls sharing of axis limits between subplots in the grid.
‘all’/True - share limits between all subplots.
‘none’/False - do not share limits between subplots.
‘row’ - share limits between subplots in the same row.
‘col’ - share limits between subplots in the same column.
- widthslist of numbers
Relative width of each column in the grid, left to right.
- heightslist of numbers
Relative height of each row in the grid, top-down.
- hspacefloat, default=4.0
Cell horizontal spacing in px.
- vspacefloat, default=4.0
Cell vertical spacing in px.
- fitbool, default=True
Whether to stretch each plot to match the aspect ratio of its cell (
fit=True), or to preserve the original aspect ratio of plots (fit=False).- alignbool, default=False
If True, align inner areas (i.e. “geom” bounds) of plots. However, cells containing other (sub)grids are not participating in the plot “inner areas” layouting.
- guidesstr, default=’auto’
Specifies how guides (legends and colorbars) should be treated in the layout.
‘collect’ - collect guides from all subplots, removing duplicates.
‘keep’ - keep guides in their original subplots; do not collect at this level.
‘auto’ - allow guides to be collected if an upper-level layout uses
guides='collect'; otherwise, keep them in subplots.
Duplicates are identified by comparing visual properties:
For legends: title, labels, and all aesthetic values (colors, shapes, sizes, etc.).
For colorbars: title, domain limits, breaks, and color gradient.
- Returns:
SupPlotsSpecThe grid specification.
Examples
1import numpy as np 2from lets_plot import * 3LetsPlot.setup_html() 4np.random.seed(42) 5n = 100 6x = np.arange(n) 7y = np.random.normal(size=n) 8w, h = 200, 150 9p = ggplot({'x': x, 'y': y}, aes(x='x', y='y')) + ggsize(w, h) 10plot_list=[ 11 gggrid([p+geom_point(), p+geom_histogram(bins=3)]), 12 p+geom_line() 13] 14gggrid(plot_list, ncol=1) + ggsize(400, 300)