{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Spines\n\nThis demo compares:\n\n- normal Axes, with spines on all four sides;\n- an Axes with spines only on the left and bottom;\n- an Axes using custom bounds to limit the extent of the spine.\n\nEach `.axes.Axes` has a list of `.Spine` objects, accessible\nvia the container ``ax.spines``.\n\n.. redirect-from:: /gallery/spines/spines_bounds\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nx = np.linspace(0, 2 * np.pi, 100)\ny = 2 * np.sin(x)\n\n# Constrained layout makes sure the labels don't overlap the Axes.\nfig, (ax0, ax1, ax2) = plt.subplots(nrows=3, layout='constrained')\n\nax0.plot(x, y)\nax0.set_title('normal spines')\n\nax1.plot(x, y)\nax1.set_title('bottom-left spines')\n\n# Hide the right and top spines\nax1.spines.right.set_visible(False)\nax1.spines.top.set_visible(False)\n\nax2.plot(x, y)\nax2.set_title('spines with bounds limited to data range')\n\n# Only draw spines for the data range, not in the margins\nax2.spines.bottom.set_bounds(x.min(), x.max())\nax2.spines.left.set_bounds(y.min(), y.max())\n# Hide the right and top spines\nax2.spines.right.set_visible(False)\nax2.spines.top.set_visible(False)\n\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. admonition:: References\n\n The use of the following functions, methods, classes and modules is shown\n in this example:\n\n - `matplotlib.artist.Artist.set_visible`\n - `matplotlib.spines.Spine.set_bounds`\n\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.2" } }, "nbformat": 4, "nbformat_minor": 0 }