.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/1single/plot_multivariate-eof.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_multivariate-eof.py: Multivariate EOF analysis ============================================ Multivariate EOF analysis. .. GENERATED FROM PYTHON SOURCE LINES 7-24 .. 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 PlateCarree from xeofs.models import EOF # Create four different dataarrayss sst = xr.tutorial.open_dataset("ersstv5")["sst"] subset1 = sst.isel(lon=slice(0, 45)) subset2 = sst.isel(lon=slice(46, 90)) subset3 = sst.isel(lon=slice(91, 135)) subset4 = sst.isel(lon=slice(136, None)) multivariate_data = [subset1, subset2, subset3, subset4] .. GENERATED FROM PYTHON SOURCE LINES 25-26 Perform the actual analysis .. GENERATED FROM PYTHON SOURCE LINES 26-32 .. code-block:: Python pca = EOF(n_modes=10, standardize=False, use_coslat=True) pca.fit(multivariate_data, dim="time") components = pca.components() scores = pca.scores() .. GENERATED FROM PYTHON SOURCE LINES 33-34 Plot mode 1 .. GENERATED FROM PYTHON SOURCE LINES 34-68 .. code-block:: Python mode = 5 proj = PlateCarree() kwargs = { "cmap": "RdBu", "vmin": -0.05, "vmax": 0.05, "transform": proj, "add_colorbar": False, } fig = plt.figure(figsize=(7.3, 6)) fig.subplots_adjust(wspace=0) gs = GridSpec(2, 4, figure=fig, width_ratios=[1, 1, 1, 1]) ax = [fig.add_subplot(gs[0, i], projection=proj) for i in range(4)] ax_pc = fig.add_subplot(gs[1, :]) # PC scores.sel(mode=mode).plot(ax=ax_pc) ax_pc.set_xlabel("") ax_pc.set_title("") # EOFs for i, (a, comps) in enumerate(zip(ax, components)): a.coastlines(color=".5") comps.sel(mode=mode).plot(ax=a, **kwargs) a.set_xticks([], []) a.set_yticks([], []) a.set_xlabel("") a.set_ylabel("") a.set_title("Subset {:}".format(i + 1)) ax[0].set_ylabel("EOFs") fig.suptitle("Mode {:}".format(mode)) plt.savefig("multivariate-eof-analysis.jpg") .. image-sg:: /auto_examples/1single/images/sphx_glr_plot_multivariate-eof_001.png :alt: Mode 5, Subset 1, Subset 2, Subset 3, Subset 4 :srcset: /auto_examples/1single/images/sphx_glr_plot_multivariate-eof_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.211 seconds) .. _sphx_glr_download_auto_examples_1single_plot_multivariate-eof.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_multivariate-eof.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_multivariate-eof.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_