

.. _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.




.. image:: /gallery/ticks_and_spines/images/sphx_glr_spines_001.png
    :align: center





.. code-block:: python

    import numpy as np
    import matplotlib.pyplot as plt


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

    fig, (ax0, ax1, ax2) = plt.subplots(nrows=3)

    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')

    # Tweak spacing between subplots to prevent labels from overlapping
    plt.subplots_adjust(hspace=0.5)
    plt.show()

**Total running time of the script:** ( 0 minutes  0.066 seconds)



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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

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

    `Generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
