{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Dropped spines\n\nDemo of spines offset from the axes (a.k.a. \"dropped spines\").\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\n\ndef adjust_spines(ax, visible_spines):\n ax.label_outer(remove_inner_ticks=True)\n ax.grid(color='0.9')\n\n for loc, spine in ax.spines.items():\n if loc in visible_spines:\n spine.set_position(('outward', 10)) # outward by 10 points\n else:\n spine.set_visible(False)\n\n\nx = np.linspace(0, 2 * np.pi, 100)\n\nfig, axs = plt.subplots(2, 2)\n\naxs[0, 0].plot(x, np.sin(x))\naxs[0, 1].plot(x, np.cos(x))\naxs[1, 0].plot(x, -np.cos(x))\naxs[1, 1].plot(x, -np.sin(x))\n\nadjust_spines(axs[0, 0], ['left'])\nadjust_spines(axs[0, 1], [])\nadjust_spines(axs[1, 0], ['left', 'bottom'])\nadjust_spines(axs[1, 1], ['bottom'])\n\nplt.show()" ] } ], "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 }