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

.. only:: html

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

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

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

.. _sphx_glr_gallery_ticks_and_spines_spines.py:


======
Spines
======

This demo compares:

- normal axes, with spines on all four sides;
- an axes with spines only on the left and bottom;
- an axes using custom bounds to limit the extent of the spine.

.. GENERATED FROM PYTHON SOURCE LINES 12-47



.. image:: /gallery/ticks_and_spines/images/sphx_glr_spines_001.png
    :alt: normal spines, bottom-left spines
    :class: sphx-glr-single-img





.. code-block:: default

    import numpy as np
    import matplotlib.pyplot as plt


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

    # Constrained layout makes sure the labels don't overlap the axes.
    fig, (ax0, ax1, ax2) = plt.subplots(nrows=3, constrained_layout=True)

    ax0.plot(x, y)
    ax0.set_title('normal spines')

    ax1.plot(x, y)
    ax1.set_title('bottom-left spines')

    # Hide the right and top spines
    ax1.spines['right'].set_visible(False)
    ax1.spines['top'].set_visible(False)
    # Only show ticks on the left and bottom spines
    ax1.yaxis.set_ticks_position('left')
    ax1.xaxis.set_ticks_position('bottom')

    ax2.plot(x, y)

    # Only draw spine between the y-ticks
    ax2.spines['left'].set_bounds(-1, 1)
    # Hide the right and top spines
    ax2.spines['right'].set_visible(False)
    ax2.spines['top'].set_visible(False)
    # Only show ticks on the left and bottom spines
    ax2.yaxis.set_ticks_position('left')
    ax2.xaxis.set_ticks_position('bottom')

    plt.show()


.. _sphx_glr_download_gallery_ticks_and_spines_spines.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: spines.py <spines.py>`



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

     :download:`Download Jupyter notebook: spines.ipynb <spines.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>`_
