# 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)

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().

Attributes
axesnumpy object array

Contains axes in corresponding position, as returned from plt.subplots

figmatplotlib.Figure

The figure containing all the axes

name_dictsnumpy 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, sharex=True, sharey=True, figsize=None, aspect=1, size=3, subplot_kws=None)
Parameters

xarray DataArray to be plotted

row, colstrings

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

col_wrapint, optional

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

sharexbool, optional

If true, the facets will share x axes

shareybool, optional

If true, the facets will share y axes

figsizetuple, optional

A tuple (width, height) of the figure in inches. If set, overrides size and aspect.

aspectscalar, optional

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

sizescalar, optional

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

subplot_kwsdict, optional

Dictionary of keyword arguments for matplotlib subplots

Methods

 __init__(data[, col, row, col_wrap, sharex, …]) Parameters add_colorbar(**kwargs) Draw a colorbar add_legend(**kwargs) 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. map_dataarray_line(func, x, y, hue[, …]) 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, size]) 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.