
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "content/user_guide/auto_examples/2cross/plot_mca.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_2cross_plot_mca.py>`
        to download the full example code

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

.. _sphx_glr_content_user_guide_auto_examples_2cross_plot_mca.py:


Maximum Covariance Analysis
===========================

Maximum Covariance Analysis (MCA) between two data sets.

.. GENERATED FROM PYTHON SOURCE LINES 7-18

.. code-block:: default


    # Load packages and data:
    import matplotlib.pyplot as plt
    import numpy as np
    import xarray as xr
    from cartopy.crs import Orthographic, PlateCarree
    from cartopy.feature import LAND
    from matplotlib.gridspec import GridSpec

    import xeofs as xe








.. GENERATED FROM PYTHON SOURCE LINES 19-20

Create 2 different DataArrays

.. GENERATED FROM PYTHON SOURCE LINES 20-25

.. code-block:: default


    t2m = xr.tutorial.load_dataset("air_temperature")["air"]
    da1 = t2m.isel(lon=slice(0, 26))
    da2 = t2m.isel(lon=slice(27, None))








.. GENERATED FROM PYTHON SOURCE LINES 26-27

Perform MCA

.. GENERATED FROM PYTHON SOURCE LINES 27-31

.. code-block:: default


    mca = xe.cross.MCA(n_modes=20, standardize=False, use_coslat=True)
    mca.fit(da1, da2, dim="time")





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

 .. code-block:: none


    <xeofs.cross.mca.MCA object at 0x7e85a02dc390>



.. GENERATED FROM PYTHON SOURCE LINES 32-34

Get singular vectors, projections (PCs), homogeneous and heterogeneous
patterns:

.. GENERATED FROM PYTHON SOURCE LINES 34-40

.. code-block:: default


    singular_vectors = mca.components()
    scores = mca.scores()
    hom_pats, pvals_hom = mca.homogeneous_patterns()
    het_pats, pvals_het = mca.heterogeneous_patterns()








.. GENERATED FROM PYTHON SOURCE LINES 41-45

When two fields are expected, the output of the above methods is a list of
length 2, with the first and second entry containing the relevant object for
``X`` and ``Y``. For example, the p-values obtained from the two-sided t-test
for the homogeneous patterns of ``X`` are:

.. GENERATED FROM PYTHON SOURCE LINES 45-48

.. code-block:: default


    pvals_hom[0]






.. 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.DataArray &#x27;pvalues_of_left_homogeneous_patterns&#x27; (mode: 20, lat: 25,
                                                              lon: 26)&gt;
    0.0 3.277e-290 2.858e-286 1.574e-271 ... 0.04195 0.08527 0.1658 0.2847
    Coordinates:
      * lat      (lat) float32 15.0 17.5 20.0 22.5 25.0 ... 65.0 67.5 70.0 72.5 75.0
      * lon      (lon) float32 200.0 202.5 205.0 207.5 ... 255.0 257.5 260.0 262.5
      * mode     (mode) int64 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
    Attributes: (18)</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'pvalues_of_left_homogeneous_patterns'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>mode</span>: 20</li><li><span class='xr-has-index'>lat</span>: 25</li><li><span class='xr-has-index'>lon</span>: 26</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-53b635a1-cf09-4a87-a396-bb5bf4b4206d' class='xr-array-in' type='checkbox' ><label for='section-53b635a1-cf09-4a87-a396-bb5bf4b4206d' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>0.0 3.277e-290 2.858e-286 1.574e-271 ... 0.04195 0.08527 0.1658 0.2847</span></div><div class='xr-array-data'><pre>array([[[0.00000000e+000, 3.27672445e-290, 2.85821727e-286, ...,
             1.30755800e-119, 9.29456258e-186, 0.00000000e+000],
            [0.00000000e+000, 0.00000000e+000, 2.87101038e-272, ...,
             8.57858735e-140, 4.38438327e-131, 6.54890891e-156],
            [0.00000000e+000, 0.00000000e+000, 0.00000000e+000, ...,
             6.15496250e-039, 9.85381563e-095, 4.89136200e-307],
            ...,
            [0.00000000e+000, 0.00000000e+000, 0.00000000e+000, ...,
             0.00000000e+000, 0.00000000e+000, 0.00000000e+000],
            [0.00000000e+000, 0.00000000e+000, 0.00000000e+000, ...,
             0.00000000e+000, 0.00000000e+000, 0.00000000e+000],
            [0.00000000e+000, 0.00000000e+000, 0.00000000e+000, ...,
             0.00000000e+000, 0.00000000e+000, 0.00000000e+000]],

           [[1.46782316e-058, 9.56859880e-069, 2.49252664e-077, ...,
             4.02041814e-067, 1.68526822e-001, 1.58221456e-054],
            [5.20140198e-051, 1.96005356e-055, 4.53132541e-063, ...,
             8.24385503e-066, 5.60159418e-142, 3.17376848e-126],
            [4.26872498e-027, 2.16850608e-023, 5.55329729e-044, ...,
             2.56963654e-302, 7.17644670e-212, 1.99410703e-056],
    ...
            [3.77487789e-015, 3.64127143e-016, 8.17340517e-016, ...,
             7.94992946e-001, 5.62426663e-001, 4.06321008e-001],
            [1.35869438e-010, 2.30333669e-010, 1.19018892e-009, ...,
             2.37227859e-001, 1.51736427e-001, 1.10405429e-001],
            [1.27479599e-009, 3.77881609e-009, 1.98575664e-008, ...,
             1.74628906e-001, 1.55246309e-001, 1.57767055e-001]],

           [[3.28384285e-001, 1.38309744e-002, 1.52551917e-002, ...,
             8.58540672e-001, 9.33288628e-005, 7.82797204e-010],
            [3.38026741e-001, 1.93722505e-001, 1.66496245e-001, ...,
             1.17130510e-003, 1.71900480e-004, 3.80443039e-006],
            [4.90610866e-001, 3.66637823e-001, 1.08555255e-001, ...,
             1.39347242e-007, 8.30137641e-005, 3.52387798e-004],
            ...,
            [9.52919132e-019, 3.98347482e-018, 4.31468626e-017, ...,
             6.60899277e-001, 6.15776281e-001, 5.84415489e-001],
            [1.16506332e-006, 4.09920575e-006, 1.49332311e-005, ...,
             8.11239592e-001, 9.16905758e-001, 9.73819891e-001],
            [3.98849543e-002, 7.44596380e-002, 1.38348520e-001, ...,
             8.52728134e-002, 1.65762408e-001, 2.84713979e-001]]])</pre></div></div></li><li class='xr-section-item'><input id='section-25dc86a2-d41d-48a8-a33f-7ffa82234086' class='xr-section-summary-in' type='checkbox'  checked><label for='section-25dc86a2-d41d-48a8-a33f-7ffa82234086' class='xr-section-summary' >Coordinates: <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 class='xr-has-index'>lat</span></div><div class='xr-var-dims'>(lat)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>15.0 17.5 20.0 ... 70.0 72.5 75.0</div><input id='attrs-baf9a840-61ea-40a0-bd02-d9a4f8831f2c' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-baf9a840-61ea-40a0-bd02-d9a4f8831f2c' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-7b368b71-d611-4c26-8fd4-3c04b3392c09' class='xr-var-data-in' type='checkbox'><label for='data-7b368b71-d611-4c26-8fd4-3c04b3392c09' 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([15. , 17.5, 20. , 22.5, 25. , 27.5, 30. , 32.5, 35. , 37.5, 40. , 42.5,
           45. , 47.5, 50. , 52.5, 55. , 57.5, 60. , 62.5, 65. , 67.5, 70. , 72.5,
           75. ], dtype=float32)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>lon</span></div><div class='xr-var-dims'>(lon)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>200.0 202.5 205.0 ... 260.0 262.5</div><input id='attrs-9bb9088a-407b-4037-a6e3-200fd24966e6' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-9bb9088a-407b-4037-a6e3-200fd24966e6' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-83be5995-a55a-43c7-b20b-4d67d325dec4' class='xr-var-data-in' type='checkbox'><label for='data-83be5995-a55a-43c7-b20b-4d67d325dec4' 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([200. , 202.5, 205. , 207.5, 210. , 212.5, 215. , 217.5, 220. , 222.5,
           225. , 227.5, 230. , 232.5, 235. , 237.5, 240. , 242.5, 245. , 247.5,
           250. , 252.5, 255. , 257.5, 260. , 262.5], dtype=float32)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>mode</span></div><div class='xr-var-dims'>(mode)</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>1 2 3 4 5 6 7 ... 15 16 17 18 19 20</div><input id='attrs-daa505c5-6e2d-444d-bd00-845190f07027' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-daa505c5-6e2d-444d-bd00-845190f07027' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-ffeac56b-8c73-404f-8504-9d7e71bc2f79' class='xr-var-data-in' type='checkbox'><label for='data-ffeac56b-8c73-404f-8504-9d7e71bc2f79' 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,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
           19, 20])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-2a786127-92cb-46b5-8ca3-1d01f5af05b6' class='xr-section-summary-in' type='checkbox'  ><label for='section-2a786127-92cb-46b5-8ca3-1d01f5af05b6' class='xr-section-summary' >Indexes: <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-index-name'><div>mode</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-5f13baa8-4d31-4e1c-8286-1bd84e0514df' class='xr-index-data-in' type='checkbox'/><label for='index-5f13baa8-4d31-4e1c-8286-1bd84e0514df' 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, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], dtype=&#x27;int64&#x27;, name=&#x27;mode&#x27;))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>lat</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-9d97d4db-41b1-4a8b-9046-287b49b6e06c' class='xr-index-data-in' type='checkbox'/><label for='index-9d97d4db-41b1-4a8b-9046-287b49b6e06c' 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([15.0, 17.5, 20.0, 22.5, 25.0, 27.5, 30.0, 32.5, 35.0, 37.5, 40.0, 42.5,
           45.0, 47.5, 50.0, 52.5, 55.0, 57.5, 60.0, 62.5, 65.0, 67.5, 70.0, 72.5,
           75.0],
          dtype=&#x27;float32&#x27;, name=&#x27;lat&#x27;))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>lon</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-48b4cbb5-4167-4ded-810a-4046e00dfb23' class='xr-index-data-in' type='checkbox'/><label for='index-48b4cbb5-4167-4ded-810a-4046e00dfb23' 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.0, 202.5, 205.0, 207.5, 210.0, 212.5, 215.0, 217.5, 220.0, 222.5,
           225.0, 227.5, 230.0, 232.5, 235.0, 237.5, 240.0, 242.5, 245.0, 247.5,
           250.0, 252.5, 255.0, 257.5, 260.0, 262.5],
          dtype=&#x27;float32&#x27;, name=&#x27;lon&#x27;))</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-534264e8-6205-4963-bfcb-ed2ab3914210' class='xr-section-summary-in' type='checkbox'  ><label for='section-534264e8-6205-4963-bfcb-ed2ab3914210' class='xr-section-summary' >Attributes: <span>(18)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'><dt><span>model :</span></dt><dd>Maximum Covariance Analysis</dd><dt><span>software :</span></dt><dd>xeofs</dd><dt><span>version :</span></dt><dd>1.2.0</dd><dt><span>date :</span></dt><dd>2024-09-04 15:06:30</dd><dt><span>n_modes :</span></dt><dd>20</dd><dt><span>center :</span></dt><dd>[&#x27;True&#x27;, &#x27;True&#x27;]</dd><dt><span>standardize :</span></dt><dd>[&#x27;False&#x27;, &#x27;False&#x27;]</dd><dt><span>use_coslat :</span></dt><dd>[&#x27;True&#x27;, &#x27;True&#x27;]</dd><dt><span>check_nans :</span></dt><dd>[&#x27;True&#x27;, &#x27;True&#x27;]</dd><dt><span>use_pca :</span></dt><dd>[&#x27;True&#x27;, &#x27;True&#x27;]</dd><dt><span>n_pca_modes :</span></dt><dd>[0.999, 0.999]</dd><dt><span>pca_init_rank_reduction :</span></dt><dd>[0.3, 0.3]</dd><dt><span>alpha :</span></dt><dd>[1.0, 1.0]</dd><dt><span>sample_name :</span></dt><dd>sample</dd><dt><span>feature_name :</span></dt><dd>[&#x27;feature1&#x27;, &#x27;feature2&#x27;]</dd><dt><span>random_state :</span></dt><dd>None</dd><dt><span>compute :</span></dt><dd>True</dd><dt><span>solver :</span></dt><dd>auto</dd></dl></div></li></ul></div></div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 49-50

Create a mask to identifiy where p-values are below 0.05

.. GENERATED FROM PYTHON SOURCE LINES 50-55

.. code-block:: default


    hom_mask = [values < 0.05 for values in pvals_hom]
    het_mask = [values < 0.05 for values in pvals_het]









.. GENERATED FROM PYTHON SOURCE LINES 56-57

Plot some relevant quantities of mode 2.

.. GENERATED FROM PYTHON SOURCE LINES 57-113

.. code-block:: default


    lonlats = [
        np.meshgrid(pvals_hom[0].lon.values, pvals_hom[0].lat.values),
        np.meshgrid(pvals_hom[1].lon.values, pvals_hom[1].lat.values),
    ]
    proj = [
        Orthographic(central_latitude=30, central_longitude=-120),
        Orthographic(central_latitude=30, central_longitude=-60),
    ]
    kwargs1 = {"cmap": "BrBG", "vmin": -0.05, "vmax": 0.05, "transform": PlateCarree()}
    kwargs2 = {"cmap": "RdBu", "vmin": -1, "vmax": 1, "transform": PlateCarree()}

    mode = 2

    fig = plt.figure(figsize=(7, 14))
    gs = GridSpec(5, 2)
    ax1 = [fig.add_subplot(gs[0, i], projection=proj[i]) for i in range(2)]
    ax2 = [fig.add_subplot(gs[1, i], projection=proj[i]) for i in range(2)]
    ax3 = [fig.add_subplot(gs[2, i], projection=proj[i]) for i in range(2)]
    ax4 = [fig.add_subplot(gs[3, i]) for i in range(2)]

    for i, a in enumerate(ax1):
        singular_vectors[i].sel(mode=mode).plot(ax=a, **kwargs1)

    for i, a in enumerate(ax2):
        hom_pats[i].sel(mode=mode).plot(ax=a, **kwargs2)
        a.scatter(
            lonlats[i][0],
            lonlats[i][1],
            hom_mask[i].sel(mode=mode).values * 0.5,
            color="k",
            alpha=0.5,
            transform=PlateCarree(),
        )
    for i, a in enumerate(ax3):
        het_pats[i].sel(mode=mode).plot(ax=a, **kwargs2)
        a.scatter(
            lonlats[i][0],
            lonlats[i][1],
            het_mask[i].sel(mode=mode).values * 0.5,
            color="k",
            alpha=0.5,
            transform=PlateCarree(),
        )

    for i, a in enumerate(ax4):
        scores[i].sel(mode=mode).plot(ax=a)
        a.set_xlabel("")


    for a in np.ravel([ax1, ax2, ax3]):
        a.coastlines(color=".5")
        a.add_feature(LAND)

    plt.tight_layout()
    plt.savefig("mca.jpg")



.. image-sg:: /content/user_guide/auto_examples/2cross/images/sphx_glr_plot_mca_001.png
   :alt: mode = 2, mode = 2, mode = 2, mode = 2, mode = 2, mode = 2, mode = 2, mode = 2
   :srcset: /content/user_guide/auto_examples/2cross/images/sphx_glr_plot_mca_001.png
   :class: sphx-glr-single-img






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

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


.. _sphx_glr_download_content_user_guide_auto_examples_2cross_plot_mca.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_mca.py <plot_mca.py>`

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

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


.. only:: html

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

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