.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/taylor_plot.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. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_taylor_plot.py: =============== o. taylor plot =============== .. currentmodule:: easy_mpl This file shows the usage of :func:`taylor_plot` function. A Taylor plot can be used to show statistical summary of one or more measurements/models. .. GENERATED FROM PYTHON SOURCE LINES 13-22 .. code-block:: Python import numpy as np from easy_mpl import taylor_plot from easy_mpl.utils import version_info version_info() # sphinx_gallery_thumbnail_number = -1 .. rst-class:: sphx-glr-script-out .. code-block:: none {'easy_mpl': '0.21.5', 'matplotlib': '3.9.4', 'numpy': '2.0.2', 'pandas': '2.2.3', 'scipy': '1.13.1'} .. GENERATED FROM PYTHON SOURCE LINES 23-47 .. code-block:: Python # The desired covariance matrix. cov = np.array( [[1, 0.8, 0.6, 0.4, 0.2], [0.8, 1.2, 0.8, 0.6, 0.4], [0.6, 0.8, 0.8, 0.8, 0.6], [0.4, 0.6, 0.8, 1.4, 0.8], [0.2, 0.4, 0.6, 0.8, 0.6]] ) # Generate the random samples. rng = np.random.default_rng(313) data = rng.multivariate_normal(np.zeros(5), cov, size=100) print(data.shape) observations = data[:, 0] simulations = {"LSTM": data[:, 1], "CNN": data[:, 2], "TCN": data[:, 3], "CNN-LSTM": data[:, 4]} _ = taylor_plot(observations=observations, simulations=simulations, title="Taylor Plot") .. image-sg:: /auto_examples/images/sphx_glr_taylor_plot_001.png :alt: Taylor Plot :srcset: /auto_examples/images/sphx_glr_taylor_plot_001.png, /auto_examples/images/sphx_glr_taylor_plot_001_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/easy-mpl/checkouts/dev/examples/taylor_plot.py:35: RuntimeWarning: covariance is not symmetric positive-semidefinite. data = rng.multivariate_normal(np.zeros(5), cov, size=100) (100, 5) .. GENERATED FROM PYTHON SOURCE LINES 48-49 multiple taylor plots in one figure .. GENERATED FROM PYTHON SOURCE LINES 49-134 .. code-block:: Python def create_data(cov, seed=313, mu=np.zeros(5), size=100): # Generate the random samples. rng = np.random.default_rng(seed) return rng.multivariate_normal(np.zeros(5), cov, size=size) cov1 = np.array( [[1, 0.8, 0.6, 0.4, 0.2], [0.8, 1.2, 0.8, 0.6, 0.4], [0.6, 0.8, 0.8, 0.8, 0.6], [0.4, 0.6, 0.8, 1.4, 0.8], [0.2, 0.4, 0.6, 0.8, 0.6]] ) cov2 = np.array( [[1, 0.8, 0.6, 0.4, 0.2], [0.8, 1.2, 0.8, 0.6, 0.4], [0.6, 0.8, 0.8, 0.8, 0.6], [0.4, 0.6, 0.8, 1.4, 0.8], [0.2, 0.4, 0.6, 0.8, 0.6]] ) cov3 = np.array( [[1, 0.8, 0.6, 0.4, 0.2], [0.8, 1.2, 0.8, 0.6, 0.4], [0.6, 0.8, 0.8, 0.8, 0.6], [0.4, 0.6, 0.8, 1.4, 0.8], [0.2, 0.4, 0.6, 0.8, 0.6]] ) cov4 = np.array( [[1, 0.8, 0.6, 0.4, 0.2], [0.8, 1.2, 0.8, 0.6, 0.4], [0.6, 0.8, 0.8, 0.8, 0.6], [0.4, 0.6, 0.8, 1.4, 0.8], [0.2, 0.4, 0.6, 0.8, 0.6]] ) site1_data = create_data(cov1) site2_data = create_data(cov2) site3_data = create_data(cov3) site4_data = create_data(cov4) observations = { 'site1': site1_data[:, 0], 'site2': site2_data[:, 0], 'site3': site3_data[:, 0], 'site4': site4_data[:, 0], } simulations = { "site1": {"LSTM": site1_data[:, 1], "CNN": site1_data[:, 2], "TCN": site1_data[:, 3], "CNN-LSTM": site1_data[:, 4]}, "site2": {"LSTM": site2_data[:, 1], "CNN": site2_data[:, 2], "TCN": site2_data[:, 3], "CNN-LSTM": site2_data[:, 4]}, "site3": {"LSTM": site3_data[:, 1], "CNN": site3_data[:, 2], "TCN": site3_data[:, 3], "CNN-LSTM": site3_data[:, 4]}, "site4": {"LSTM": site4_data[:, 1], "CNN": site4_data[:, 2], "TCN": site4_data[:, 3], "CNN-LSTM": site4_data[:, 4]}, } # define positions of subplots rects = dict(site1=221, site2=222, site3=223, site4=224) _ = taylor_plot(observations=observations, simulations=simulations, axis_locs=rects, plot_bias=True, cont_kws={'colors': 'blue', 'linewidths': 1.0, 'linestyles': 'dotted'}, grid_kws={'axis': 'x', 'color': 'g', 'lw': 1.0}, title="mutiple subplots") .. image-sg:: /auto_examples/images/sphx_glr_taylor_plot_002.png :alt: mutiple subplots, Site1, Site2, Site3, Site4 :srcset: /auto_examples/images/sphx_glr_taylor_plot_002.png, /auto_examples/images/sphx_glr_taylor_plot_002_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/easy-mpl/checkouts/dev/examples/taylor_plot.py:55: RuntimeWarning: covariance is not symmetric positive-semidefinite. return rng.multivariate_normal(np.zeros(5), cov, size=size) .. GENERATED FROM PYTHON SOURCE LINES 135-136 using statistics instead of arrays .. GENERATED FROM PYTHON SOURCE LINES 136-150 .. code-block:: Python observations = {'std': 3.5} predictions = { # pbias is optional 'Model 1': {'std': 2.80068, 'corr_coeff': 0.49172, 'pbias': -8.85}, 'Model 2': {'std': 3.8, 'corr_coeff': 0.67, 'pbias': -19.76}, 'Model 3': {'std': 3.9, 'corr_coeff': 0.596, 'pbias': 7.81}, 'Model 4': {'std': 2.36, 'corr_coeff': 0.27, 'pbias': -22.78}, 'Model 5': {'std': 2.97, 'corr_coeff': 0.452, 'pbias': -7.99}} _ = taylor_plot(observations, predictions) .. image-sg:: /auto_examples/images/sphx_glr_taylor_plot_003.png :alt: taylor plot :srcset: /auto_examples/images/sphx_glr_taylor_plot_003.png, /auto_examples/images/sphx_glr_taylor_plot_003_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 151-152 with customized markers .. GENERATED FROM PYTHON SOURCE LINES 152-174 .. code-block:: Python cov = np.array( [[1, 0.8, 0.6, 0.4, 0.2], [0.8, 1.2, 0.8, 0.6, 0.4], [0.6, 0.8, 0.8, 0.8, 0.6], [0.4, 0.6, 0.8, 1.4, 0.8], [0.2, 0.4, 0.6, 0.8, 0.6]] ) data = create_data(cov) observations = data[:, 0] simulations = {"LSTM": data[:, 1], "CNN": data[:, 2], "TCN": data[:, 3], "CNN-LSTM": data[:, 4]} _ = taylor_plot(observations=observations, simulations=simulations, marker_kws={'markersize': 10, 'markeredgewidth': 1.5, 'markeredgecolor': 'black', 'lw': 0.0}) .. image-sg:: /auto_examples/images/sphx_glr_taylor_plot_004.png :alt: taylor plot :srcset: /auto_examples/images/sphx_glr_taylor_plot_004.png, /auto_examples/images/sphx_glr_taylor_plot_004_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 175-176 with customizing bbox .. GENERATED FROM PYTHON SOURCE LINES 176-186 .. code-block:: Python _ = taylor_plot(observations=observations, simulations=simulations, title="custom_legend", leg_kws={'facecolor': 'white', 'edgecolor': 'black','bbox_to_anchor':(0.80, 1.1), 'fontsize': 14, 'labelspacing': 1.0}, marker_kws = {'ms':'20', 'markeredgecolor': 'k', 'lw': 0.0}, ) .. image-sg:: /auto_examples/images/sphx_glr_taylor_plot_005.png :alt: custom_legend :srcset: /auto_examples/images/sphx_glr_taylor_plot_005.png, /auto_examples/images/sphx_glr_taylor_plot_005_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 187-190 using extended horizontal axis to show the points which have negative correlation. we can also change axis labels .. GENERATED FROM PYTHON SOURCE LINES 190-202 .. code-block:: Python np.random.seed(313) observations = np.random.normal(20, 40, 10) simus = {"LSTM": np.random.normal(20, 40, 10), "CNN": np.random.normal(20, 40, 10), "TCN": np.random.normal(20, 40, 10), "CNN-LSTM": np.random.normal(20, 40, 10)} taylor_plot(observations=observations, simulations=simus, extend=True, corr_alias='Corr.', std_alias='Std. Dev.') .. image-sg:: /auto_examples/images/sphx_glr_taylor_plot_006.png :alt: taylor plot :srcset: /auto_examples/images/sphx_glr_taylor_plot_006.png, /auto_examples/images/sphx_glr_taylor_plot_006_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.824 seconds) .. _sphx_glr_download_auto_examples_taylor_plot.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/sphinx-gallery/sphinx-gallery.github.io/master?urlpath=lab/tree/notebooks/auto_examples/taylor_plot.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: taylor_plot.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: taylor_plot.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: taylor_plot.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_