# xarray.plot.FacetGrid

### *class* xarray.plot.FacetGrid(data, col=None, row=None, col_wrap=None, sharex=True, sharey=True, figsize=None, aspect=1, size=3, subplot_kws=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/plot/facetgrid.py#L89-L1073)

Initialize the Matplotlib figure and FacetGrid object.

The [`FacetGrid`](#xarray.plot.FacetGrid) is an object that links an xarray DataArray to
a Matplotlib figure with a particular structure.

In particular, [`FacetGrid`](#xarray.plot.FacetGrid) is used to draw plots with multiple
axes, where each axes shows the same relationship conditioned on
different levels of some dimension. It’s possible to condition on up to
two variables by assigning variables to the rows and columns of the
grid.

The general approach to plotting here is called “small multiples”,
where the same kind of plot is repeated multiple times, and the
specific use of small multiples to display the same relationship
conditioned on one or more other variables is often called a “trellis
plot”.

The basic workflow is to initialize the [`FacetGrid`](#xarray.plot.FacetGrid) object with
the DataArray and the variable names that are used to structure the grid.
Then plotting functions can be applied to each subset by calling
[`FacetGrid.map_dataarray()`](xarray.plot.FacetGrid.map_dataarray.html.md#xarray.plot.FacetGrid.map_dataarray) or [`FacetGrid.map()`](xarray.plot.FacetGrid.map.html.md#xarray.plot.FacetGrid.map).

#### axs

Array containing axes in corresponding position, as returned from
[`matplotlib.pyplot.subplots()`](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html#matplotlib.pyplot.subplots).

* **Type:**
  [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray) of [`matplotlib.axes.Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes)

#### col_labels

Column titles.

* **Type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list) of [`matplotlib.text.Annotation`](https://matplotlib.org/stable/api/text_api.html#matplotlib.text.Annotation)

#### row_labels

Row titles.

* **Type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list) of [`matplotlib.text.Annotation`](https://matplotlib.org/stable/api/text_api.html#matplotlib.text.Annotation)

#### fig

The figure containing all the axes.

* **Type:**
  [`matplotlib.figure.Figure`](https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure)

#### name_dicts

Array containing dictionaries mapping coordinate names to values. `None` is
used as a sentinel value for axes that should remain empty, i.e.,
sometimes the rightmost grid positions in the bottom row.

* **Type:**
  [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray) of [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)

#### \_\_init_\_(data, col=None, row=None, col_wrap=None, sharex=True, sharey=True, figsize=None, aspect=1, size=3, subplot_kws=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/plot/facetgrid.py#L154-L320)

* **Parameters:**
  * **data** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray) or [`Dataset`](xarray.Dataset.html.md#xarray.Dataset)) – DataArray or Dataset to be plotted.
  * **row, col** ([hashable](../user-guide/terminology.html.md#term-name) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – Dimension names that define subsets of the data, which will be drawn
    on separate facets in the grid.
  * **col_wrap** ([`int`](https://docs.python.org/3/builtins/functions.html#int), [`None`](https://docs.python.org/3/builtins/constants.html#None) or `"auto"`, *optional*) – “Wrap” the grid for the column variable after this number of columns,
    adding rows if `col_wrap` is less than the number of facets.
    If “auto” align the grid to the figsize or keep it as square as possible.
  * **sharex** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`True`](https://docs.python.org/3/builtins/constants.html#True)) – If true, the facets will share *x* axes.
  * **sharey** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`True`](https://docs.python.org/3/builtins/constants.html#True)) – If true, the facets will share *y* axes.
  * **figsize** (`Iterable` of [`float`](https://docs.python.org/3/builtins/functions.html#float) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – A tuple (width, height) of the figure in inches.
    If set, overrides `size` and `aspect`.
  * **aspect** ([scalar](../user-guide/terminology.html.md#term-scalar), *default*: `1`) – Aspect ratio of each facet, so that `aspect * size` gives the
    width of each facet in inches.
  * **size** ([scalar](../user-guide/terminology.html.md#term-scalar), *default*: `3`) – Height (in inches) of each facet. See also: `aspect`.
  * **subplot_kws** ([`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), *optional*) – Dictionary of keyword arguments for Matplotlib subplots
    ([`matplotlib.pyplot.subplots()`](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html#matplotlib.pyplot.subplots)).

### Methods

| [`__init__`](#xarray.plot.FacetGrid.__init__)(data[, col, row, col_wrap, sharex, ...])                                   |                                                                |
|--------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------|
| [`add_colorbar`](xarray.plot.FacetGrid.add_colorbar.html.md#xarray.plot.FacetGrid.add_colorbar)(\*\*kwargs)                         | Draw a colorbar.                                               |
| [`add_legend`](xarray.plot.FacetGrid.add_legend.html.md#xarray.plot.FacetGrid.add_legend)(\*[, label, use_legend_elements])       |                                                                |
| [`add_quiverkey`](xarray.plot.FacetGrid.add_quiverkey.html.md#xarray.plot.FacetGrid.add_quiverkey)(u, v, \*\*kwargs)                 |                                                                |
| [`map`](xarray.plot.FacetGrid.map.html.md#xarray.plot.FacetGrid.map)(func, \*args, \*\*kwargs)                             | Apply a plotting function to each facet's subset of the data.  |
| [`map_dataarray`](xarray.plot.FacetGrid.map_dataarray.html.md#xarray.plot.FacetGrid.map_dataarray)(func, x, y, \*\*kwargs)           | Apply a plotting function to a 2d facet's subset of the data.  |
| [`map_dataarray_line`](xarray.plot.FacetGrid.map_dataarray_line.html.md#xarray.plot.FacetGrid.map_dataarray_line)(func, x, y, hue[, ...]) |                                                                |
| [`map_dataset`](xarray.plot.FacetGrid.map_dataset.html.md#xarray.plot.FacetGrid.map_dataset)(func[, x, y, hue, hue_style, ...])    |                                                                |
| [`map_plot1d`](xarray.plot.FacetGrid.map_plot1d.html.md#xarray.plot.FacetGrid.map_plot1d)(func, x, y, \*[, z, hue, ...])          | Apply a plotting function to a 1d facet's subset of the data.  |
| [`set_axis_labels`](xarray.plot.FacetGrid.set_axis_labels.html.md#xarray.plot.FacetGrid.set_axis_labels)(\*axlabels)                   | Set axis labels on the left column and bottom row of the grid. |
| [`set_ticks`](xarray.plot.FacetGrid.set_ticks.html.md#xarray.plot.FacetGrid.set_ticks)([max_xticks, max_yticks, fontsize])       | Set and control tick behavior.                                 |
| [`set_titles`](xarray.plot.FacetGrid.set_titles.html.md#xarray.plot.FacetGrid.set_titles)([template, maxchar, size])              | Draw titles either above each facet or on the grid margins.    |
| [`set_xlabels`](xarray.plot.FacetGrid.set_xlabels.html.md#xarray.plot.FacetGrid.set_xlabels)([label])                              | Label the x axis on the bottom row of the grid.                |
| [`set_ylabels`](xarray.plot.FacetGrid.set_ylabels.html.md#xarray.plot.FacetGrid.set_ylabels)([label])                              | Label the y axis on the left column of the grid.               |
| `set_zlabels`([label])                                                                                                               | Label the z axis.                                              |

### Attributes

| `axes`                                                      |    |
|-------------------------------------------------------------|----|
| `data`                                                      |    |
| [`name_dicts`](#xarray.plot.FacetGrid.name_dicts) |    |
| [`fig`](#xarray.plot.FacetGrid.fig)        |    |
| [`axs`](#xarray.plot.FacetGrid.axs)        |    |
| `row_names`                                                 |    |
| `col_names`                                                 |    |
| `figlegend`                                                 |    |
| `quiverkey`                                                 |    |
| `cbar`                                                      |    |
| [`row_labels`](#xarray.plot.FacetGrid.row_labels) |    |
| [`col_labels`](#xarray.plot.FacetGrid.col_labels) |    |
