.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/spines/spines.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_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. Each `.axes.Axes` has a list of `.Spine` objects, accessible via the container ``ax.spines``. .. redirect-from:: /gallery/spines/spines_bounds .. GENERATED FROM PYTHON SOURCE LINES 18-49 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np 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, layout='constrained') 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) ax2.plot(x, y) ax2.set_title('spines with bounds limited to data range') # Only draw spines for the data range, not in the margins ax2.spines.bottom.set_bounds(x.min(), x.max()) ax2.spines.left.set_bounds(y.min(), y.max()) # Hide the right and top spines ax2.spines.right.set_visible(False) ax2.spines.top.set_visible(False) plt.show() .. image-sg:: /gallery/spines/images/sphx_glr_spines_001.png :alt: normal spines, bottom-left spines, spines with bounds limited to data range :srcset: /gallery/spines/images/sphx_glr_spines_001.png, /gallery/spines/images/sphx_glr_spines_001_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 50-57 .. admonition:: References The use of the following functions, methods, classes and modules is shown in this example: - `matplotlib.artist.Artist.set_visible` - `matplotlib.spines.Spine.set_bounds` .. _sphx_glr_download_gallery_spines_spines.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: spines.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: spines.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_