# xarray.set_options

### *class* xarray.set_options(\*\*kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/options.py#L185-L446)

Set options for xarray in a controlled context.

* **Parameters:**
  * **arithmetic_broadcast** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`True`](https://docs.python.org/3/builtins/constants.html#True)) – Whether to perform automatic broadcasting in binary operations.
  * **arithmetic_compat** (`{"identical", "equals", "broadcast_equals", "no_conflicts", "override", "minimal"}`, *default*: `"minimal"`) – How to compare non-index coordinates of the same name for potential
    conflicts when performing binary operations. (For the alignment of index
    coordinates in binary operations, see arithmetic_join.)

    Allowed values are:
    - `"identical"`: all values, dimensions and attributes of the coordinates
      must be the same.
    - `"equals"`: all values and dimensions of the coordinates must be the
      same.
    - `"broadcast_equals"`: all values of the coordinates must be equal after
      broadcasting to ensure common dimensions.
    - `"no_conflicts"`: only values which are not null in both coordinates
      must be equal. The returned coordinate then contains the combination
      of all non-null values.
    - `"override"`: skip comparing and take the coordinates from the first
      operand.
    - `"minimal"`: drop conflicting coordinates.
  * **arithmetic_join** (`{"inner", "outer", "left", "right", "exact"}`, *default*: `"inner"`) – DataArray/Dataset index alignment in binary operations.

    Allowed values are:
    - `"outer"`: use the union of object indexes
    - `"inner"`: use the intersection of object indexes
    - `"left"`: use indexes from the first object with each dimension
    - `"right"`: use indexes from the last object with each dimension
    - `"exact"`: instead of aligning, raise ValueError when indexes to be
      aligned are not equal
  * **chunk_manager** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str), *default*: `"dask"`) – Chunk manager to use for chunked array computations when multiple
    options are installed.
  * **cmap_divergent** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) or [`matplotlib.colors.Colormap`](https://matplotlib.org/stable/api/_as_gen/matplotlib.colors.Colormap.html#matplotlib.colors.Colormap), *default*: `"RdBu_r"`) – Colormap to use for divergent data plots. If string, must be a
    matplotlib built-in colormap. Can also be a Colormap object
    (e.g. `mpl.colormaps["magma"]`).
  * **cmap_sequential** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) or [`matplotlib.colors.Colormap`](https://matplotlib.org/stable/api/_as_gen/matplotlib.colors.Colormap.html#matplotlib.colors.Colormap), *default*: `"viridis"`) – Colormap to use for non-divergent data plots. If string, must be a
    matplotlib built-in colormap. Can also be a Colormap object
    (e.g. `mpl.colormaps["magma"]`).
  * **display_default_indexes** (`{"default", True, False}`, *default*: [`False`](https://docs.python.org/3/builtins/constants.html#False)) – Whether to show default indexes, i.e. `PandasIndex` and
    `PandasMultiIndex`, in the indexes section of the repr of
    `DataArray`, `Dataset` and `DataTree` objects. `"default"` hides
    them, like `False`.
  * **display_expand_attrs** (`{"default", True, False}`, *default*: `"default"`) – Whether to expand the attributes section for display of
    `DataArray` or `Dataset` objects.

    Allowed values are:
    * `True` : always expand attrs
    * `False` : always collapse attrs
    * `"default"` : expand unless over a pre-defined limit
  * **display_expand_coords** (`{"default", True, False}`, *default*: `"default"`) – Whether to expand the coordinates section for display of
    `DataArray` or `Dataset` objects.

    Allowed values are:
    * `True` : always expand coordinates
    * `False` : always collapse coordinates
    * `"default"` : expand unless over a pre-defined limit
  * **display_expand_data** (`{"default", True, False}`, *default*: `"default"`) – Whether to expand the data section for display of `DataArray`
    objects.

    Allowed values are:
    * `True` : always expand data
    * `False` : always collapse data
    * `"default"` : expand unless over a pre-defined limit
  * **display_expand_data_vars** (`{"default", True, False}`, *default*: `"default"`) – Whether to expand the data variables section for display of
    `Dataset` objects.

    Allowed values are:
    * `True` : always expand data variables
    * `False` : always collapse data variables
    * `"default"` : expand unless over a pre-defined limit
  * **display_expand_groups** (`{"default", True, False}`, *default*: `"default"`) – Has no effect since the HTML repr of `DataTree` was reworked in
    v2026.01.0. Use `display_max_children` and
    `display_max_html_elements` to limit the displayed groups instead.
  * **display_expand_indexes** (`{"default", True, False}`, *default*: `"default"`) – Whether to expand the indexes section for display of
    `DataArray` or `Dataset` objects.

    Allowed values are:
    * `True` : always expand indexes
    * `False` : always collapse indexes
    * `"default"` : expand unless over a pre-defined limit
      (always collapse for HTML style)
  * **display_max_children** ([`int`](https://docs.python.org/3/builtins/functions.html#int), *default*: `12`) – Maximum number of children to display for each node in a DataTree.
  * **display_max_html_elements** ([`int`](https://docs.python.org/3/builtins/functions.html#int), *default*: `300`) – Maximum number of HTML elements to include in DataTree HTML displays.
    Additional items are truncated.
  * **display_max_rows** ([`int`](https://docs.python.org/3/builtins/functions.html#int), *default*: `12`) – Maximum display rows.
  * **display_max_items** ([`int`](https://docs.python.org/3/builtins/functions.html#int), *default*: `20`) – Maximum number of items to display for a DataTree before collapsing
    child nodes, across all levels.
  * **display_values_threshold** ([`int`](https://docs.python.org/3/builtins/functions.html#int), *default*: `200`) – Total number of array elements which trigger summarization rather
    than full repr for variable data views (NumPy arrays).
  * **display_style** (`{"text", "html"}`, *default*: `"html"`) – Display style to use in Jupyter for xarray objects.
  * **display_width** ([`int`](https://docs.python.org/3/builtins/functions.html#int), *default*: `80`) – Maximum display width for `repr` on xarray objects.
  * **facetgrid_figsize** (`{"computed", "rcparams"}` or [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple) of [`float`](https://docs.python.org/3/builtins/functions.html#float), *default*: `"computed"`) – How [`FacetGrid`](xarray.plot.FacetGrid.html.md#xarray.plot.FacetGrid) determines figure size when
    `figsize` is not explicitly passed:
    * `"computed"` : figure size is derived from `size` and `aspect`
      parameters (current default behavior).
    * `"rcparams"` : use `matplotlib.rcParams['figure.figsize']` as the
      total figure size.
    * `(width, height)` : use a fixed figure size (in inches).
  * **file_cache_maxsize** ([`int`](https://docs.python.org/3/builtins/functions.html#int), *default*: `128`) – Maximum number of open files to hold in xarray’s global
    least-recently-used cache. This should be smaller than your system’s
    per-process file descriptor limit (e.g., `ulimit -n` on Linux).
  * **keep_attrs** (`{"default", True, False}`, *default*: `"default"`) – Whether to keep attributes on xarray Datasets/DataArrays after
    operations.

    Allowed values are:
    * `True` : always keep attrs
    * `False` : always discard attrs
    * `"default"` : keep attrs only in unambiguous circumstances
  * **netcdf_engine_order** ([sequence](https://docs.python.org/3/glossary.html#term-sequence) of `{"netcdf4", "h5netcdf", "scipy"}`) – Preference order of backend engines to use when reading or writing
    netCDF files with `open_dataset()` and `to_netcdf()` if `engine`
    is not explicitly specified. May be any permutation or subset of the
    allowed values.

    Default is `("netcdf4", "h5netcdf", "scipy")`.
  * **use_bottleneck** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`False`](https://docs.python.org/3/builtins/constants.html#False)) – Whether to use `bottleneck` to accelerate 1D reductions and
    1D rolling reduction operations.
  * **use_flox** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`True`](https://docs.python.org/3/builtins/constants.html#True)) – Whether to use `numpy_groupies` and `flox` to accelerate
    groupby and resampling reductions.
  * **use_new_combine_kwarg_defaults** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`False`](https://docs.python.org/3/builtins/constants.html#False)) – Whether to use new kwarg default values for combine functions:
    [`concat()`](xarray.concat.html.md#xarray.concat), [`merge()`](xarray.merge.html.md#xarray.merge),
    [`open_mfdataset()`](xarray.open_mfdataset.html.md#xarray.open_mfdataset). New values are:
    * `data_vars`: None
    * `coords`: “minimal”
    * `compat`: “override”
    * `join`: “exact”
  * **use_numbagg** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`True`](https://docs.python.org/3/builtins/constants.html#True)) – Whether to use `numbagg` to accelerate reductions.
    Takes precedence over `use_bottleneck` when both are True.
  * **use_opt_einsum** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`True`](https://docs.python.org/3/builtins/constants.html#True)) – Whether to use `opt_einsum` to accelerate dot products.
  * **warn_for_unclosed_files** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`False`](https://docs.python.org/3/builtins/constants.html#False)) – Whether or not to issue a warning when unclosed files are deallocated.
    This is mostly useful for debugging.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('54e4191c-5514-44a0-9506-8b62921785f2','51c98281-0aea-46a1-93b3-b2ccf57c169e','c688fee3-0e90-4aa8-a0a5-26045a7a6345','../lite/tree/../notebooks/index.html?path=88bdef2b_5735_41c8_bf79_832bb5973c87.ipynb','None')">Try it in your browser!</button></div>

It is possible to use `set_options` either as a context manager:

```pycon
>>> ds = xr.Dataset({"x": np.arange(1000)})
>>> with xr.set_options(display_width=40):
...     print(ds)
...
<xarray.Dataset> Size: 8kB
Dimensions:  (x: 1000)
Coordinates:
  * x        (x) int64 8kB 0 1 ... 999
Data variables:
    *empty*
```

Or to set global options:

```pycon
>>> xr.set_options(display_width=80)
<xarray.core.options.set_options object at 0x...>
```

<div id="c688fee3-0e90-4aa8-a0a5-26045a7a6345" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('54e4191c-5514-44a0-9506-8b62921785f2','c688fee3-0e90-4aa8-a0a5-26045a7a6345')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('54e4191c-5514-44a0-9506-8b62921785f2','c688fee3-0e90-4aa8-a0a5-26045a7a6345')">Open In Tab</button></div><div id="51c98281-0aea-46a1-93b3-b2ccf57c169e" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### \_\_init_\_(\*\*kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/options.py#L409-L434)

### Methods

| [`__init__`](#xarray.set_options.__init__)(\*\*kwargs)   |    |
|-------------------------------------------------------------------------|----|
