{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Nested GridSpecs\n\nThis example demonstrates the use of nested `.GridSpec`\\s.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\n\ndef squiggle_xy(a, b, c, d):\n i = np.arange(0.0, 2*np.pi, 0.05)\n return np.sin(i*a)*np.cos(i*b), np.sin(i*c)*np.cos(i*d)\n\n\nfig = plt.figure(figsize=(8, 8))\nouter_grid = fig.add_gridspec(4, 4, wspace=0, hspace=0)\n\nfor a in range(4):\n for b in range(4):\n # gridspec inside gridspec\n inner_grid = outer_grid[a, b].subgridspec(3, 3, wspace=0, hspace=0)\n axs = inner_grid.subplots() # Create all subplots for the inner grid.\n for (c, d), ax in np.ndenumerate(axs):\n ax.plot(*squiggle_xy(a + 1, b + 1, c + 1, d + 1))\n ax.set(xticks=[], yticks=[])\n\n# show only the outside spines\nfor ax in fig.get_axes():\n ss = ax.get_subplotspec()\n ax.spines.top.set_visible(ss.is_first_row())\n ax.spines.bottom.set_visible(ss.is_last_row())\n ax.spines.left.set_visible(ss.is_first_col())\n ax.spines.right.set_visible(ss.is_last_col())\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 }