🍾 Xarray is now 10 years old! 🎉

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

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

axs#

Array containing axes in corresponding position, as returned from matplotlib.pyplot.subplots().

Type:

ndarray of matplotlib.axes.Axes

col_labels#

Column titles.

Type:

list of matplotlib.text.Annotation

row_labels#

Row titles.

Type:

list of matplotlib.text.Annotation

fig#

The figure containing all the axes.

Type:

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 of dict

__init__(data, col=None, row=None, col_wrap=None, sharex=True, sharey=True, figsize=None, aspect=1, size=3, subplot_kws=None)[source]#
Parameters:
  • data (DataArray or Dataset) – DataArray or Dataset to be plotted.

  • row, col (str) – Dimension names that define subsets of the data, which will be drawn on separate facets in the grid.

  • col_wrap (int, optional) – “Wrap” the grid the for the column variable after this number of columns, adding rows if col_wrap is less than the number of facets.

  • sharex (bool, optional) – If true, the facets will share x axes.

  • sharey (bool, optional) – If true, the facets will share y axes.

  • figsize (Iterable of float or None, optional) – A tuple (width, height) of the figure in inches. If set, overrides size and aspect.

  • aspect (scalar, default: 1) – Aspect ratio of each facet, so that aspect * size gives the width of each facet in inches.

  • size (scalar, default: 3) – Height (in inches) of each facet. See also: aspect.

  • subplot_kws (dict, optional) – Dictionary of keyword arguments for Matplotlib subplots (matplotlib.pyplot.subplots()).

Methods

__init__(data[, col, row, col_wrap, sharex, ...])

Parameters:

add_colorbar(**kwargs)

Draw a colorbar.

add_legend(*[, label, use_legend_elements])

add_quiverkey(u, v, **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[, ...])

map_dataset(func[, x, y, hue, hue_style, ...])

map_plot1d(func, x, y, *[, z, hue, ...])

Apply a plotting function to a 1d facet's subset of the data.

set_axis_labels(*axlabels)

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.

set_zlabels([label])

Label the z axis.

Attributes

axes

data

name_dicts

fig

axs

row_names

col_names

figlegend

quiverkey

cbar

row_labels

col_labels