
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/axisartist/demo_curvelinear_grid2.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_gallery_axisartist_demo_curvelinear_grid2.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_axisartist_demo_curvelinear_grid2.py:


======================
Demo Curvelinear Grid2
======================

Custom grid and ticklines.

This example demonstrates how to use GridHelperCurveLinear to define
custom grids and ticklines by applying a transformation on the grid.
As showcase on the plot, a 5x5 matrix is displayed on the axes.

.. GENERATED FROM PYTHON SOURCE LINES 12-57



.. image:: /gallery/axisartist/images/sphx_glr_demo_curvelinear_grid2_001.png
    :alt: demo curvelinear grid2
    :class: sphx-glr-single-img





.. code-block:: default


    import numpy as np
    import matplotlib.pyplot as plt

    from mpl_toolkits.axisartist.grid_helper_curvelinear import (
        GridHelperCurveLinear)
    from mpl_toolkits.axisartist.grid_finder import (
        ExtremeFinderSimple, MaxNLocator)
    from mpl_toolkits.axisartist.axislines import Subplot


    def curvelinear_test1(fig):
        """Grid for custom transform."""

        def tr(x, y):
            sgn = np.sign(x)
            x, y = np.abs(np.asarray(x)), np.asarray(y)
            return sgn*x**.5, y

        def inv_tr(x, y):
            sgn = np.sign(x)
            x, y = np.asarray(x), np.asarray(y)
            return sgn*x**2, y

        grid_helper = GridHelperCurveLinear(
            (tr, inv_tr),
            extreme_finder=ExtremeFinderSimple(20, 20),
            # better tick density
            grid_locator1=MaxNLocator(nbins=6), grid_locator2=MaxNLocator(nbins=6))

        ax1 = Subplot(fig, 111, grid_helper=grid_helper)
        # ax1 will have a ticks and gridlines defined by the given
        # transform (+ transData of the Axes). Note that the transform of the Axes
        # itself (i.e., transData) is not affected by the given transform.

        fig.add_subplot(ax1)

        ax1.imshow(np.arange(25).reshape(5, 5),
                   vmax=50, cmap=plt.cm.gray_r, origin="lower")


    if __name__ == "__main__":
        fig = plt.figure(figsize=(7, 4))
        curvelinear_test1(fig)
        plt.show()


.. _sphx_glr_download_gallery_axisartist_demo_curvelinear_grid2.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download sphx-glr-download-python

     :download:`Download Python source code: demo_curvelinear_grid2.py <demo_curvelinear_grid2.py>`



  .. container:: sphx-glr-download sphx-glr-download-jupyter

     :download:`Download Jupyter notebook: demo_curvelinear_grid2.ipynb <demo_curvelinear_grid2.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
