.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/1single/plot_eof-smode.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_1single_plot_eof-smode.py: EOF analysis (S-mode) ======================== EOF analysis in S-mode maximises the temporal variance. .. GENERATED FROM PYTHON SOURCE LINES 7-16 .. code-block:: Python # Load packages and data: import xarray as xr import matplotlib.pyplot as plt from matplotlib.gridspec import GridSpec from cartopy.crs import EqualEarth, PlateCarree from xeofs.models import EOF .. GENERATED FROM PYTHON SOURCE LINES 17-20 .. code-block:: Python sst = xr.tutorial.open_dataset("ersstv5")["sst"] .. GENERATED FROM PYTHON SOURCE LINES 21-22 Perform the actual analysis .. GENERATED FROM PYTHON SOURCE LINES 22-30 .. code-block:: Python model = EOF(n_modes=5, use_coslat=True) model.fit(sst, dim="time") expvar = model.explained_variance() expvar_ratio = model.explained_variance_ratio() components = model.components() scores = model.scores() .. GENERATED FROM PYTHON SOURCE LINES 31-32 Explained variance fraction .. GENERATED FROM PYTHON SOURCE LINES 32-36 .. code-block:: Python print("Explained variance: ", expvar.round(0).values) print("Relative: ", (expvar_ratio * 100).round(1).values) .. rst-class:: sphx-glr-script-out .. code-block:: none Explained variance: [24398. 1066. 676. 407. 303.] Relative: [85.5 3.7 2.4 1.4 1.1] .. GENERATED FROM PYTHON SOURCE LINES 37-38 Create figure showing the first two modes .. GENERATED FROM PYTHON SOURCE LINES 38-56 .. code-block:: Python proj = EqualEarth(central_longitude=180) kwargs = {"cmap": "RdBu", "vmin": -0.05, "vmax": 0.05, "transform": PlateCarree()} fig = plt.figure(figsize=(10, 8)) gs = GridSpec(3, 2, width_ratios=[1, 2]) ax0 = [fig.add_subplot(gs[i, 0]) for i in range(3)] ax1 = [fig.add_subplot(gs[i, 1], projection=proj) for i in range(3)] for i, (a0, a1) in enumerate(zip(ax0, ax1)): scores.sel(mode=i + 1).plot(ax=a0) a1.coastlines(color=".5") components.sel(mode=i + 1).plot(ax=a1, **kwargs) a0.set_xlabel("") plt.tight_layout() plt.savefig("eof-smode.jpg") .. image-sg:: /auto_examples/1single/images/sphx_glr_plot_eof-smode_001.png :alt: mode = 1, mode = 2, mode = 3, mode = 1, mode = 2, mode = 3 :srcset: /auto_examples/1single/images/sphx_glr_plot_eof-smode_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.207 seconds) .. _sphx_glr_download_auto_examples_1single_plot_eof-smode.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_eof-smode.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_eof-smode.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_