.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/10_normalizer/02_compare.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_examples_10_normalizer_02_compare.py: Normalizer Comparison --------------------- Let's compare the transformation behavior of the provided normalizers. But first, we define a convenience routine and make some imports as always. .. GENERATED FROM PYTHON SOURCE LINES 9-21 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import gstools as gs def dashes(i=1, max_n=12, width=1): """Return line dashes.""" return i * [width, width] + [max_n * 2 * width - 2 * i * width, width] .. GENERATED FROM PYTHON SOURCE LINES 22-27 We select 4 normalizers depending on a single parameter lambda and plot their transformation behavior within the interval [-5, 5]. For the shape parameter lambda, we create a list of 8 values ranging from -1 to 2.5. .. GENERATED FROM PYTHON SOURCE LINES 27-36 .. code-block:: Python lmbdas = [i * 0.5 for i in range(-2, 6)] normalizers = [ gs.normalizer.BoxCox, gs.normalizer.YeoJohnson, gs.normalizer.Modulus, gs.normalizer.Manly, ] .. GENERATED FROM PYTHON SOURCE LINES 37-38 Let's plot them! .. GENERATED FROM PYTHON SOURCE LINES 38-64 .. code-block:: Python fig, ax = plt.subplots(2, 2, figsize=[8, 8]) for i, norm in enumerate(normalizers): # correctly setting the data range x_rng = norm().normalize_range x = np.linspace(max(-5, x_rng[0] + 0.01), min(5, x_rng[1] - 0.01)) for j, lmbda in enumerate(lmbdas): ax.flat[i].plot( x, norm(lmbda=lmbda).normalize(x), label=r"$\lambda=" + str(lmbda) + "$", color="k", alpha=0.2 + j * 0.1, dashes=dashes(j), ) # axis formatting ax.flat[i].grid(which="both", color="grey", linestyle="-", alpha=0.2) ax.flat[i].set_ylim((-5, 5)) ax.flat[i].set_xlim((-5, 5)) ax.flat[i].set_title(norm().name) # figure formatting handles, labels = ax.flat[-1].get_legend_handles_labels() fig.legend(handles, labels, loc="lower center", ncol=4, handlelength=3.0) fig.suptitle("Normalizer Comparison", fontsize=20) fig.show() .. image-sg:: /examples/10_normalizer/images/sphx_glr_02_compare_001.png :alt: Normalizer Comparison, BoxCox, YeoJohnson, Modulus, Manly :srcset: /examples/10_normalizer/images/sphx_glr_02_compare_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 65-68 The missing :any:`LogNormal` transformation is covered by the :any:`BoxCox` transformation for lambda=0. The :any:`BoxCoxShift` transformation is simply the :any:`BoxCox` transformation shifted on the X-axis. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.219 seconds) .. _sphx_glr_download_examples_10_normalizer_02_compare.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 02_compare.ipynb <02_compare.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02_compare.py <02_compare.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 02_compare.zip <02_compare.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_