.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/scales/asinh_demo.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_scales_asinh_demo.py: ============ Asinh Demo ============ Illustration of the `asinh <.scale.AsinhScale>` axis scaling, which uses the transformation .. math:: a \rightarrow a_0 \sinh^{-1} (a / a_0) For coordinate values close to zero (i.e. much smaller than the "linear width" :math:`a_0`), this leaves values essentially unchanged: .. math:: a \rightarrow a + \mathcal{O}(a^3) but for larger values (i.e. :math:`|a| \gg a_0`, this is asymptotically .. math:: a \rightarrow a_0 \, \mathrm{sgn}(a) \ln |a| + \mathcal{O}(1) As with the `symlog <.scale.SymmetricalLogScale>` scaling, this allows one to plot quantities that cover a very wide dynamic range that includes both positive and negative values. However, ``symlog`` involves a transformation that has discontinuities in its gradient because it is built from *separate* linear and logarithmic transformations. The ``asinh`` scaling uses a transformation that is smooth for all (finite) values, which is both mathematically cleaner and reduces visual artifacts associated with an abrupt transition between linear and logarithmic regions of the plot. .. note:: `.scale.AsinhScale` is experimental, and the API may change. See `~.scale.AsinhScale`, `~.scale.SymmetricalLogScale`. .. GENERATED FROM PYTHON SOURCE LINES 42-49 .. code-block:: default import numpy as np import matplotlib.pyplot as plt # Prepare sample values for variations on y=x graph: x = np.linspace(-3, 6, 500) .. GENERATED FROM PYTHON SOURCE LINES 50-52 Compare "symlog" and "asinh" behaviour on sample y=x graph, where there is a discontinuous gradient in "symlog" near y=2: .. GENERATED FROM PYTHON SOURCE LINES 52-66 .. code-block:: default fig1 = plt.figure() ax0, ax1 = fig1.subplots(1, 2, sharex=True) ax0.plot(x, x) ax0.set_yscale('symlog') ax0.grid() ax0.set_title('symlog') ax1.plot(x, x) ax1.set_yscale('asinh') ax1.grid() ax1.set_title('asinh') .. image-sg:: /gallery/scales/images/sphx_glr_asinh_demo_001.png :alt: symlog, asinh :srcset: /gallery/scales/images/sphx_glr_asinh_demo_001.png, /gallery/scales/images/sphx_glr_asinh_demo_001_2_0x.png 2.0x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 1.0, 'asinh') .. GENERATED FROM PYTHON SOURCE LINES 67-68 Compare "asinh" graphs with different scale parameter "linear_width": .. GENERATED FROM PYTHON SOURCE LINES 68-80 .. code-block:: default fig2 = plt.figure(constrained_layout=True) axs = fig2.subplots(1, 3, sharex=True) for ax, (a0, base) in zip(axs, ((0.2, 2), (1.0, 0), (5.0, 10))): ax.set_title('linear_width={:.3g}'.format(a0)) ax.plot(x, x, label='y=x') ax.plot(x, 10*x, label='y=10x') ax.plot(x, 100*x, label='y=100x') ax.set_yscale('asinh', linear_width=a0, base=base) ax.grid() ax.legend(loc='best', fontsize='small') .. image-sg:: /gallery/scales/images/sphx_glr_asinh_demo_002.png :alt: linear_width=0.2, linear_width=1, linear_width=5 :srcset: /gallery/scales/images/sphx_glr_asinh_demo_002.png, /gallery/scales/images/sphx_glr_asinh_demo_002_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 81-85 Compare "symlog" and "asinh" scalings on 2D Cauchy-distributed random numbers, where one may be able to see more subtle artifacts near y=2 due to the gradient-discontinuity in "symlog": .. GENERATED FROM PYTHON SOURCE LINES 85-103 .. code-block:: default fig3 = plt.figure() ax = fig3.subplots(1, 1) r = 3 * np.tan(np.random.uniform(-np.pi / 2.02, np.pi / 2.02, size=(5000,))) th = np.random.uniform(0, 2*np.pi, size=r.shape) ax.scatter(r * np.cos(th), r * np.sin(th), s=4, alpha=0.5) ax.set_xscale('asinh') ax.set_yscale('symlog') ax.set_xlabel('asinh') ax.set_ylabel('symlog') ax.set_title('2D Cauchy random deviates') ax.set_xlim(-50, 50) ax.set_ylim(-50, 50) ax.grid() plt.show() .. image-sg:: /gallery/scales/images/sphx_glr_asinh_demo_003.png :alt: 2D Cauchy random deviates :srcset: /gallery/scales/images/sphx_glr_asinh_demo_003.png, /gallery/scales/images/sphx_glr_asinh_demo_003_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 104-109 .. admonition:: References - `matplotlib.scale.AsinhScale` - `matplotlib.ticker.AsinhLocator` - `matplotlib.scale.SymmetricalLogScale` .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 2.229 seconds) .. _sphx_glr_download_gallery_scales_asinh_demo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: asinh_demo.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: asinh_demo.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_