.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/1single/plot_mreof.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_mreof.py: Varimax-rotated Multivariate EOF analysis ============================================ Multivariate EOF analysis with additional Varimax rotation. .. 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 PlateCarree from xeofs.models import EOF, EOFRotator .. GENERATED FROM PYTHON SOURCE LINES 17-18 Create four different dataarrayss .. GENERATED FROM PYTHON SOURCE LINES 18-24 .. code-block:: Python 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)) .. GENERATED FROM PYTHON SOURCE LINES 25-26 Perform the actual analysis .. GENERATED FROM PYTHON SOURCE LINES 26-35 .. code-block:: Python multivariate_data = [subset1, subset2, subset3, subset4] mpca = EOF(n_modes=100, standardize=False, use_coslat=True) mpca.fit(multivariate_data, dim="time") rotator = EOFRotator(n_modes=20) rotator.fit(mpca) rcomponents = rotator.components() rscores = rotator.scores() .. GENERATED FROM PYTHON SOURCE LINES 36-37 Plot mode 1 .. GENERATED FROM PYTHON SOURCE LINES 37-71 .. 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 rscores.sel(mode=mode).plot(ax=ax_pc) ax_pc.set_xlabel("") ax_pc.set_title("") # EOFs for i, (a, comps) in enumerate(zip(ax, rcomponents)): 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("mreof-analysis.jpg") .. image-sg:: /auto_examples/1single/images/sphx_glr_plot_mreof_001.png :alt: Mode 5, Subset 1, Subset 2, Subset 3, Subset 4 :srcset: /auto_examples/1single/images/sphx_glr_plot_mreof_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.727 seconds) .. _sphx_glr_download_auto_examples_1single_plot_mreof.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_mreof.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_mreof.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_