class xarray.plot.FacetGrid(data, col=None, row=None, col_wrap=None, aspect=1, size=3, subplot_kws=None)

Initialize the matplotlib figure and FacetGrid object.

The FacetGrid is an object that links a xarray DataArray to a matplotlib figure with a particular structure.

In particular, 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 ore more other variables is often called a “trellis plot”.

The basic workflow is to initialize the 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() or FacetGrid.map().


axes (numpy object array) Contains axes in corresponding position, as returned from plt.subplots
fig (matplotlib.Figure) The figure containing all the axes
name_dicts (numpy object array) Contains dictionaries mapping coordinate names to values. None is used as a sentinel value for axes which should remain empty, ie. sometimes the bottom right grid
__init__(data, col=None, row=None, col_wrap=None, aspect=1, size=3, subplot_kws=None)

data : DataArray

xarray DataArray to be plotted

row, col : strings

Dimesion names that define subsets of the data, which will be drawn on separate facets in the grid.

col_wrap : int, optional

“Wrap” the column variable at this width, so that the column facets

aspect : scalar, optional

Aspect ratio of each facet, so that aspect * size gives the width of each facet in inches

size : scalar, optional

Height (in inches) of each facet. See also: aspect

subplot_kws : dict, optional

Dictionary of keyword arguments for matplotlib subplots


__init__(data[, col, row, col_wrap, aspect, ...])
add_colorbar(**kwargs) Draw a colorbar
map(func, *args, **kwargs) Apply a plotting function to each facet’s subset of the data.
map_dataarray(func, x, y, **kwargs) Apply a plotting function to a 2d facet’s subset of the data.
set_axis_labels([x_var, y_var]) Set axis labels on the left column and bottom row of the grid.
set_ticks([max_xticks, max_yticks, fontsize]) Set and control tick behavior
set_titles([template, maxchar]) Draw titles either above each facet or on the grid margins.
set_xlabels([label]) Label the x axis on the bottom row of the grid.
set_ylabels([label]) Label the y axis on the left column of the grid.