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

.. only:: html

    .. meta::
        :keywords: codex

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

        :ref:`Go to the end <sphx_glr_download_gallery_spines_spine_placement_demo.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_spines_spine_placement_demo.py:


===============
Spine placement
===============

The position of the axis spines can be influenced using `~.Spine.set_position`.

Note: If you want to obtain arrow heads at the ends of the axes, also check
out the :doc:`/gallery/spines/centered_spines_with_arrows` example.

.. GENERATED FROM PYTHON SOURCE LINES 11-14

.. code-block:: Python

    import matplotlib.pyplot as plt
    import numpy as np








.. GENERATED FROM PYTHON SOURCE LINES 15-53

.. code-block:: Python


    x = np.linspace(0, 2*np.pi, 100)
    y = 2 * np.sin(x)

    fig, ax_dict = plt.subplot_mosaic(
        [['center', 'zero'],
         ['axes', 'data']]
    )
    fig.suptitle('Spine positions')


    ax = ax_dict['center']
    ax.set_title("'center'")
    ax.plot(x, y)
    ax.spines[['left', 'bottom']].set_position('center')
    ax.spines[['top', 'right']].set_visible(False)

    ax = ax_dict['zero']
    ax.set_title("'zero'")
    ax.plot(x, y)
    ax.spines[['left', 'bottom']].set_position('zero')
    ax.spines[['top', 'right']].set_visible(False)

    ax = ax_dict['axes']
    ax.set_title("'axes' (0.2, 0.2)")
    ax.plot(x, y)
    ax.spines.left.set_position(('axes', 0.2))
    ax.spines.bottom.set_position(('axes', 0.2))
    ax.spines[['top', 'right']].set_visible(False)

    ax = ax_dict['data']
    ax.set_title("'data' (1, 2)")
    ax.plot(x, y)
    ax.spines.left.set_position(('data', 1))
    ax.spines.bottom.set_position(('data', 2))
    ax.spines[['top', 'right']].set_visible(False)

    plt.show()



.. image-sg:: /gallery/spines/images/sphx_glr_spine_placement_demo_001.png
   :alt: Spine positions, 'center', 'zero', 'axes' (0.2, 0.2), 'data' (1, 2)
   :srcset: /gallery/spines/images/sphx_glr_spine_placement_demo_001.png, /gallery/spines/images/sphx_glr_spine_placement_demo_001_2_00x.png 2.00x
   :class: sphx-glr-single-img






.. _sphx_glr_download_gallery_spines_spine_placement_demo.py:

.. only:: html

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

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

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

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

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: spine_placement_demo.zip <spine_placement_demo.zip>`


.. only:: html

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

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
