
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "content/user_guide/auto_examples/1single/plot_complex_eof.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_content_user_guide_auto_examples_1single_plot_complex_eof.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_content_user_guide_auto_examples_1single_plot_complex_eof.py:


Complex EOF analysis
============================================

In this tutorial, we'll walk through how to perform a Complex EOF analysis on
the zonal and meridional wind components.

Let's start by importing the necessary packages and loading the data:

.. GENERATED FROM PYTHON SOURCE LINES 12-19

.. code-block:: default

    import matplotlib.pyplot as plt
    import xarray as xr

    import xeofs as xe

    xr.set_options(display_expand_attrs=False)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    <xarray.core.options.set_options object at 0x7e85b3262450>



.. GENERATED FROM PYTHON SOURCE LINES 20-21

For this example, we'll use the ERA-Interim tutorial dataset ``eraint_uvz``:

.. GENERATED FROM PYTHON SOURCE LINES 21-25

.. code-block:: default


    uvz = xr.tutorial.open_dataset("eraint_uvz")
    uvz






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div><svg style="position: absolute; width: 0; height: 0; overflow: hidden">
    <defs>
    <symbol id="icon-database" viewBox="0 0 32 32">
    <path d="M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z"></path>
    <path d="M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
    <path d="M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
    </symbol>
    <symbol id="icon-file-text2" viewBox="0 0 32 32">
    <path d="M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z"></path>
    <path d="M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
    <path d="M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
    <path d="M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
    </symbol>
    </defs>
    </svg>
    <style>/* CSS stylesheet for displaying xarray objects in jupyterlab.
     *
     */

    :root {
      --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));
      --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));
      --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));
      --xr-border-color: var(--jp-border-color2, #e0e0e0);
      --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);
      --xr-background-color: var(--jp-layout-color0, white);
      --xr-background-color-row-even: var(--jp-layout-color1, white);
      --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);
    }

    html[theme=dark],
    body[data-theme=dark],
    body.vscode-dark {
      --xr-font-color0: rgba(255, 255, 255, 1);
      --xr-font-color2: rgba(255, 255, 255, 0.54);
      --xr-font-color3: rgba(255, 255, 255, 0.38);
      --xr-border-color: #1F1F1F;
      --xr-disabled-color: #515151;
      --xr-background-color: #111111;
      --xr-background-color-row-even: #111111;
      --xr-background-color-row-odd: #313131;
    }

    .xr-wrap {
      display: block !important;
      min-width: 300px;
      max-width: 700px;
    }

    .xr-text-repr-fallback {
      /* fallback to plain text repr when CSS is not injected (untrusted notebook) */
      display: none;
    }

    .xr-header {
      padding-top: 6px;
      padding-bottom: 6px;
      margin-bottom: 4px;
      border-bottom: solid 1px var(--xr-border-color);
    }

    .xr-header > div,
    .xr-header > ul {
      display: inline;
      margin-top: 0;
      margin-bottom: 0;
    }

    .xr-obj-type,
    .xr-array-name {
      margin-left: 2px;
      margin-right: 10px;
    }

    .xr-obj-type {
      color: var(--xr-font-color2);
    }

    .xr-sections {
      padding-left: 0 !important;
      display: grid;
      grid-template-columns: 150px auto auto 1fr 20px 20px;
    }

    .xr-section-item {
      display: contents;
    }

    .xr-section-item input {
      display: none;
    }

    .xr-section-item input + label {
      color: var(--xr-disabled-color);
    }

    .xr-section-item input:enabled + label {
      cursor: pointer;
      color: var(--xr-font-color2);
    }

    .xr-section-item input:enabled + label:hover {
      color: var(--xr-font-color0);
    }

    .xr-section-summary {
      grid-column: 1;
      color: var(--xr-font-color2);
      font-weight: 500;
    }

    .xr-section-summary > span {
      display: inline-block;
      padding-left: 0.5em;
    }

    .xr-section-summary-in:disabled + label {
      color: var(--xr-font-color2);
    }

    .xr-section-summary-in + label:before {
      display: inline-block;
      content: '►';
      font-size: 11px;
      width: 15px;
      text-align: center;
    }

    .xr-section-summary-in:disabled + label:before {
      color: var(--xr-disabled-color);
    }

    .xr-section-summary-in:checked + label:before {
      content: '▼';
    }

    .xr-section-summary-in:checked + label > span {
      display: none;
    }

    .xr-section-summary,
    .xr-section-inline-details {
      padding-top: 4px;
      padding-bottom: 4px;
    }

    .xr-section-inline-details {
      grid-column: 2 / -1;
    }

    .xr-section-details {
      display: none;
      grid-column: 1 / -1;
      margin-bottom: 5px;
    }

    .xr-section-summary-in:checked ~ .xr-section-details {
      display: contents;
    }

    .xr-array-wrap {
      grid-column: 1 / -1;
      display: grid;
      grid-template-columns: 20px auto;
    }

    .xr-array-wrap > label {
      grid-column: 1;
      vertical-align: top;
    }

    .xr-preview {
      color: var(--xr-font-color3);
    }

    .xr-array-preview,
    .xr-array-data {
      padding: 0 5px !important;
      grid-column: 2;
    }

    .xr-array-data,
    .xr-array-in:checked ~ .xr-array-preview {
      display: none;
    }

    .xr-array-in:checked ~ .xr-array-data,
    .xr-array-preview {
      display: inline-block;
    }

    .xr-dim-list {
      display: inline-block !important;
      list-style: none;
      padding: 0 !important;
      margin: 0;
    }

    .xr-dim-list li {
      display: inline-block;
      padding: 0;
      margin: 0;
    }

    .xr-dim-list:before {
      content: '(';
    }

    .xr-dim-list:after {
      content: ')';
    }

    .xr-dim-list li:not(:last-child):after {
      content: ',';
      padding-right: 5px;
    }

    .xr-has-index {
      font-weight: bold;
    }

    .xr-var-list,
    .xr-var-item {
      display: contents;
    }

    .xr-var-item > div,
    .xr-var-item label,
    .xr-var-item > .xr-var-name span {
      background-color: var(--xr-background-color-row-even);
      margin-bottom: 0;
    }

    .xr-var-item > .xr-var-name:hover span {
      padding-right: 5px;
    }

    .xr-var-list > li:nth-child(odd) > div,
    .xr-var-list > li:nth-child(odd) > label,
    .xr-var-list > li:nth-child(odd) > .xr-var-name span {
      background-color: var(--xr-background-color-row-odd);
    }

    .xr-var-name {
      grid-column: 1;
    }

    .xr-var-dims {
      grid-column: 2;
    }

    .xr-var-dtype {
      grid-column: 3;
      text-align: right;
      color: var(--xr-font-color2);
    }

    .xr-var-preview {
      grid-column: 4;
    }

    .xr-index-preview {
      grid-column: 2 / 5;
      color: var(--xr-font-color2);
    }

    .xr-var-name,
    .xr-var-dims,
    .xr-var-dtype,
    .xr-preview,
    .xr-attrs dt {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      padding-right: 10px;
    }

    .xr-var-name:hover,
    .xr-var-dims:hover,
    .xr-var-dtype:hover,
    .xr-attrs dt:hover {
      overflow: visible;
      width: auto;
      z-index: 1;
    }

    .xr-var-attrs,
    .xr-var-data,
    .xr-index-data {
      display: none;
      background-color: var(--xr-background-color) !important;
      padding-bottom: 5px !important;
    }

    .xr-var-attrs-in:checked ~ .xr-var-attrs,
    .xr-var-data-in:checked ~ .xr-var-data,
    .xr-index-data-in:checked ~ .xr-index-data {
      display: block;
    }

    .xr-var-data > table {
      float: right;
    }

    .xr-var-name span,
    .xr-var-data,
    .xr-index-name div,
    .xr-index-data,
    .xr-attrs {
      padding-left: 25px !important;
    }

    .xr-attrs,
    .xr-var-attrs,
    .xr-var-data,
    .xr-index-data {
      grid-column: 1 / -1;
    }

    dl.xr-attrs {
      padding: 0;
      margin: 0;
      display: grid;
      grid-template-columns: 125px auto;
    }

    .xr-attrs dt,
    .xr-attrs dd {
      padding: 0;
      margin: 0;
      float: left;
      padding-right: 10px;
      width: auto;
    }

    .xr-attrs dt {
      font-weight: normal;
      grid-column: 1;
    }

    .xr-attrs dt:hover span {
      display: inline-block;
      background: var(--xr-background-color);
      padding-right: 10px;
    }

    .xr-attrs dd {
      grid-column: 2;
      white-space: pre-wrap;
      word-break: break-all;
    }

    .xr-icon-database,
    .xr-icon-file-text2,
    .xr-no-icon {
      display: inline-block;
      vertical-align: middle;
      width: 1em;
      height: 1.5em !important;
      stroke-width: 0;
      stroke: currentColor;
      fill: currentColor;
    }
    </style><pre class='xr-text-repr-fallback'>&lt;xarray.Dataset&gt;
    Dimensions:    (longitude: 480, latitude: 241, level: 3, month: 2)
    Coordinates:
      * longitude  (longitude) float32 -180.0 -179.2 -178.5 ... 177.8 178.5 179.2
      * latitude   (latitude) float32 90.0 89.25 88.5 87.75 ... -88.5 -89.25 -90.0
      * level      (level) int32 200 500 850
      * month      (month) int32 1 7
    Data variables:
        z          (month, level, latitude, longitude) float64 ...
        u          (month, level, latitude, longitude) float64 ...
        v          (month, level, latitude, longitude) float64 ...
    Attributes: (2)</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.Dataset</div></div><ul class='xr-sections'><li class='xr-section-item'><input id='section-1f737158-62e3-4cea-b91d-bd45e8b31b0b' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-1f737158-62e3-4cea-b91d-bd45e8b31b0b' class='xr-section-summary'  title='Expand/collapse section'>Dimensions:</label><div class='xr-section-inline-details'><ul class='xr-dim-list'><li><span class='xr-has-index'>longitude</span>: 480</li><li><span class='xr-has-index'>latitude</span>: 241</li><li><span class='xr-has-index'>level</span>: 3</li><li><span class='xr-has-index'>month</span>: 2</li></ul></div><div class='xr-section-details'></div></li><li class='xr-section-item'><input id='section-c28eb6d6-9003-4087-bbf3-469990e61eea' class='xr-section-summary-in' type='checkbox'  checked><label for='section-c28eb6d6-9003-4087-bbf3-469990e61eea' class='xr-section-summary' >Coordinates: <span>(4)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>longitude</span></div><div class='xr-var-dims'>(longitude)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>-180.0 -179.2 ... 178.5 179.2</div><input id='attrs-25922efc-fa50-4f05-a13c-dc113692a98b' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-25922efc-fa50-4f05-a13c-dc113692a98b' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-dec1f968-f43a-4738-9ab3-e0a399e16987' class='xr-var-data-in' type='checkbox'><label for='data-dec1f968-f43a-4738-9ab3-e0a399e16987' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>units :</span></dt><dd>degrees_east</dd><dt><span>long_name :</span></dt><dd>longitude</dd></dl></div><div class='xr-var-data'><pre>array([-180.  , -179.25, -178.5 , ...,  177.75,  178.5 ,  179.25],
          dtype=float32)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>latitude</span></div><div class='xr-var-dims'>(latitude)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>90.0 89.25 88.5 ... -89.25 -90.0</div><input id='attrs-c633dcde-6e81-46b5-9ff1-e7e7cfe50b6c' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-c633dcde-6e81-46b5-9ff1-e7e7cfe50b6c' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-78e4a615-b7d7-4624-a3a3-804dd49b266a' class='xr-var-data-in' type='checkbox'><label for='data-78e4a615-b7d7-4624-a3a3-804dd49b266a' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>units :</span></dt><dd>degrees_north</dd><dt><span>long_name :</span></dt><dd>latitude</dd></dl></div><div class='xr-var-data'><pre>array([ 90.  ,  89.25,  88.5 , ..., -88.5 , -89.25, -90.  ], dtype=float32)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>level</span></div><div class='xr-var-dims'>(level)</div><div class='xr-var-dtype'>int32</div><div class='xr-var-preview xr-preview'>200 500 850</div><input id='attrs-3df4dfa9-7b90-4a0d-87f2-79d60be05ac7' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-3df4dfa9-7b90-4a0d-87f2-79d60be05ac7' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-c2818a03-640f-458c-810f-300e853d0d63' class='xr-var-data-in' type='checkbox'><label for='data-c2818a03-640f-458c-810f-300e853d0d63' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>units :</span></dt><dd>millibars</dd><dt><span>long_name :</span></dt><dd>pressure_level</dd></dl></div><div class='xr-var-data'><pre>array([200, 500, 850], dtype=int32)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>month</span></div><div class='xr-var-dims'>(month)</div><div class='xr-var-dtype'>int32</div><div class='xr-var-preview xr-preview'>1 7</div><input id='attrs-b4c1b5c5-8766-40f8-a0f2-a64c89b77233' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-b4c1b5c5-8766-40f8-a0f2-a64c89b77233' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-50bf6efe-446a-44f8-bba0-1ffc47b0bc9b' class='xr-var-data-in' type='checkbox'><label for='data-50bf6efe-446a-44f8-bba0-1ffc47b0bc9b' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([1, 7], dtype=int32)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-ba46a4f1-908c-4325-819e-621b9796a7fc' class='xr-section-summary-in' type='checkbox'  checked><label for='section-ba46a4f1-908c-4325-819e-621b9796a7fc' class='xr-section-summary' >Data variables: <span>(3)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span>z</span></div><div class='xr-var-dims'>(month, level, latitude, longitude)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-42bd4ba8-1c27-49ae-a390-6beec693b1a5' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-42bd4ba8-1c27-49ae-a390-6beec693b1a5' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-54cf2878-db0a-45a4-a263-a5a5a571a73c' class='xr-var-data-in' type='checkbox'><label for='data-54cf2878-db0a-45a4-a263-a5a5a571a73c' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>number_of_significant_digits :</span></dt><dd>5</dd><dt><span>units :</span></dt><dd>m**2 s**-2</dd><dt><span>long_name :</span></dt><dd>Geopotential</dd><dt><span>standard_name :</span></dt><dd>geopotential</dd></dl></div><div class='xr-var-data'><pre>[694080 values with dtype=float64]</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>u</span></div><div class='xr-var-dims'>(month, level, latitude, longitude)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-94f8f900-bbef-48be-b671-093742abb6fe' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-94f8f900-bbef-48be-b671-093742abb6fe' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-e92072eb-d355-4d4f-8bd6-9d4b46523669' class='xr-var-data-in' type='checkbox'><label for='data-e92072eb-d355-4d4f-8bd6-9d4b46523669' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>number_of_significant_digits :</span></dt><dd>2</dd><dt><span>units :</span></dt><dd>m s**-1</dd><dt><span>long_name :</span></dt><dd>U component of wind</dd><dt><span>standard_name :</span></dt><dd>eastward_wind</dd></dl></div><div class='xr-var-data'><pre>[694080 values with dtype=float64]</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>v</span></div><div class='xr-var-dims'>(month, level, latitude, longitude)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-9a1e222f-0056-4c75-ade0-1af28df03d6f' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-9a1e222f-0056-4c75-ade0-1af28df03d6f' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-fdaf70be-33e7-48f8-a924-130fd119857d' class='xr-var-data-in' type='checkbox'><label for='data-fdaf70be-33e7-48f8-a924-130fd119857d' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>number_of_significant_digits :</span></dt><dd>2</dd><dt><span>units :</span></dt><dd>m s**-1</dd><dt><span>long_name :</span></dt><dd>V component of wind</dd><dt><span>standard_name :</span></dt><dd>northward_wind</dd></dl></div><div class='xr-var-data'><pre>[694080 values with dtype=float64]</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-5f68bc20-7cfc-4f40-bc22-710fc34c862b' class='xr-section-summary-in' type='checkbox'  ><label for='section-5f68bc20-7cfc-4f40-bc22-710fc34c862b' class='xr-section-summary' >Indexes: <span>(4)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-index-name'><div>longitude</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-2579e50d-d93f-415a-8aa9-cb0d65f5dc08' class='xr-index-data-in' type='checkbox'/><label for='index-2579e50d-d93f-415a-8aa9-cb0d65f5dc08' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([ -180.0, -179.25,  -178.5, -177.75,  -177.0, -176.25,  -175.5, -174.75,
            -174.0, -173.25,
           ...
             172.5,  173.25,   174.0,  174.75,   175.5,  176.25,   177.0,  177.75,
             178.5,  179.25],
          dtype=&#x27;float32&#x27;, name=&#x27;longitude&#x27;, length=480))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>latitude</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-8be3a590-f2b1-477c-b227-620ac374475c' class='xr-index-data-in' type='checkbox'/><label for='index-8be3a590-f2b1-477c-b227-620ac374475c' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([  90.0,  89.25,   88.5,  87.75,   87.0,  86.25,   85.5,  84.75,   84.0,
            83.25,
           ...
           -83.25,  -84.0, -84.75,  -85.5, -86.25,  -87.0, -87.75,  -88.5, -89.25,
            -90.0],
          dtype=&#x27;float32&#x27;, name=&#x27;latitude&#x27;, length=241))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>level</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-f3fb3921-2c58-4c26-83fc-a2c0ed50232e' class='xr-index-data-in' type='checkbox'/><label for='index-f3fb3921-2c58-4c26-83fc-a2c0ed50232e' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([200, 500, 850], dtype=&#x27;int32&#x27;, name=&#x27;level&#x27;))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>month</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-7d912219-8872-4ad9-a462-00f9bab9a0f1' class='xr-index-data-in' type='checkbox'/><label for='index-7d912219-8872-4ad9-a462-00f9bab9a0f1' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([1, 7], dtype=&#x27;int32&#x27;, name=&#x27;month&#x27;))</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-d7559453-7fce-4a13-be2b-293015d76390' class='xr-section-summary-in' type='checkbox'  ><label for='section-d7559453-7fce-4a13-be2b-293015d76390' class='xr-section-summary' >Attributes: <span>(2)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'><dt><span>Conventions :</span></dt><dd>CF-1.0</dd><dt><span>Info :</span></dt><dd>Monthly ERA-Interim data. Downloaded and edited by fabien.maussion@uibk.ac.at</dd></dl></div></li></ul></div></div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 26-32

This dataset contains the zonal, meridional, and vertical wind components at
three different atmospheric levels. Note that the data only covers two months,
so we have just two time steps (samples). While this isn't enough for a robust
EOF analysis, we'll proceed for demonstration purposes. Now, let's combine the
zonal (``u``) and meridional (``v``) wind components into a complex-valued
dataset:

.. GENERATED FROM PYTHON SOURCE LINES 32-35

.. code-block:: default


    Z = uvz["u"] + 1j * uvz["v"]








.. GENERATED FROM PYTHON SOURCE LINES 36-42

Next, we'll initialize and fit the ``ComplexEOF`` model to our data. The
``xeofs`` package makes this easy by allowing us to specify the sample
dimension (``month``), automatically performing the Complex EOF analysis
across all three atmospheric levels. As a standard practice, we'll also weigh
each grid cell by the square root of the cosine of the latitude
(``use_coslat=True``).

.. GENERATED FROM PYTHON SOURCE LINES 42-46

.. code-block:: default


    model = xe.single.ComplexEOF(n_modes=1, use_coslat=True, random_state=7)
    model.fit(Z, dim="month")





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    /home/nrieger/miniconda3/envs/xeofs/lib/python3.11/site-packages/scipy/sparse/linalg/_eigen/_svds.py:483: UserWarning: The problem size 2 minus the constraints size 0 is too small relative to the block size 1. Using a dense eigensolver instead of LOBPCG iterations.No output of the history of the iterations.
      _, eigvec = lobpcg(XH_X, X, tol=tol ** 2, maxiter=maxiter,

    <xeofs.single.eof.ComplexEOF object at 0x7e85b3299950>



.. GENERATED FROM PYTHON SOURCE LINES 47-50

Instead of just extracting the complex-valued components, we can also get the
amplitude and phase of these components. Let's start by looking at the
amplitude of the first mode:

.. GENERATED FROM PYTHON SOURCE LINES 50-58

.. code-block:: default



    spatial_ampltiudes = model.components_amplitude()
    spatial_phases = model.components_phase()

    spatial_ampltiudes.sel(mode=1).plot(col="level")
    plt.show()




.. image-sg:: /content/user_guide/auto_examples/1single/images/sphx_glr_plot_complex_eof_001.png
   :alt: level = 200, level = 500, level = 850
   :srcset: /content/user_guide/auto_examples/1single/images/sphx_glr_plot_complex_eof_001.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 59-64

It looks like the first mode picks up a pattern resembling the location of the
subtropical jet stream around ±30º latitude, particularly strong in the upper
troposphere at 200 hPa and weaker toward the surface. We can also plot the
phase of the first mode. To keep the plot clear, we'll only show the phase
where the amplitude is above a certain threshold (e.g., 0.004):

.. GENERATED FROM PYTHON SOURCE LINES 64-69

.. code-block:: default


    relevant_phases = spatial_phases.where(spatial_ampltiudes > 0.004)
    relevant_phases.sel(mode=1).plot(col="level", cmap="twilight")
    plt.show()




.. image-sg:: /content/user_guide/auto_examples/1single/images/sphx_glr_plot_complex_eof_002.png
   :alt: level = 200, level = 500, level = 850
   :srcset: /content/user_guide/auto_examples/1single/images/sphx_glr_plot_complex_eof_002.png
   :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 1.180 seconds)


.. _sphx_glr_download_content_user_guide_auto_examples_1single_plot_complex_eof.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example




    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_complex_eof.py <plot_complex_eof.py>`

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_complex_eof.ipynb <plot_complex_eof.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
