{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Demo Axes Grid\n\nGrid of 2x2 images with a single colorbar or with one colorbar per Axes.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\n\nfrom matplotlib import cbook\nfrom mpl_toolkits.axes_grid1 import ImageGrid\n\nfig = plt.figure(figsize=(10.5, 2.5))\nZ = cbook.get_sample_data(\"axes_grid/bivariate_normal.npy\")  # 15x15 array\nextent = (-3, 4, -4, 3)\n\n\n# A grid of 2x2 images with 0.05 inch pad between images and only the\n# lower-left Axes is labeled.\ngrid = ImageGrid(\n    fig, 141,  # similar to fig.add_subplot(141).\n     nrows_ncols=(2, 2), axes_pad=0.05, label_mode=\"1\")\nfor ax in grid:\n    ax.imshow(Z, extent=extent)\n# This only affects Axes in first column and second row as share_all=False.\ngrid.axes_llc.set(xticks=[-2, 0, 2], yticks=[-2, 0, 2])\n\n\n# A grid of 2x2 images with a single colorbar.\ngrid = ImageGrid(\n    fig, 142,  # similar to fig.add_subplot(142).\n    nrows_ncols=(2, 2), axes_pad=0.0, label_mode=\"L\", share_all=True,\n    cbar_location=\"top\", cbar_mode=\"single\")\nfor ax in grid:\n    im = ax.imshow(Z, extent=extent)\ngrid.cbar_axes[0].colorbar(im)\nfor cax in grid.cbar_axes:\n    cax.tick_params(labeltop=False)\n# This affects all Axes as share_all = True.\ngrid.axes_llc.set(xticks=[-2, 0, 2], yticks=[-2, 0, 2])\n\n\n# A grid of 2x2 images. Each image has its own colorbar.\ngrid = ImageGrid(\n    fig, 143,  # similar to fig.add_subplot(143).\n    nrows_ncols=(2, 2), axes_pad=0.1, label_mode=\"1\", share_all=True,\n    cbar_location=\"top\", cbar_mode=\"each\", cbar_size=\"7%\", cbar_pad=\"2%\")\nfor ax, cax in zip(grid, grid.cbar_axes):\n    im = ax.imshow(Z, extent=extent)\n    cax.colorbar(im)\n    cax.tick_params(labeltop=False)\n# This affects all Axes as share_all = True.\ngrid.axes_llc.set(xticks=[-2, 0, 2], yticks=[-2, 0, 2])\n\n\n# A grid of 2x2 images. Each image has its own colorbar.\ngrid = ImageGrid(\n    fig, 144,  # similar to fig.add_subplot(144).\n    nrows_ncols=(2, 2), axes_pad=(0.45, 0.15), label_mode=\"1\", share_all=True,\n    cbar_location=\"right\", cbar_mode=\"each\", cbar_size=\"7%\", cbar_pad=\"2%\")\n# Use a different colorbar range every time\nlimits = ((0, 1), (-2, 2), (-1.7, 1.4), (-1.5, 1))\nfor ax, cax, vlim in zip(grid, grid.cbar_axes, limits):\n    im = ax.imshow(Z, extent=extent, vmin=vlim[0], vmax=vlim[1])\n    cb = cax.colorbar(im)\n    cb.set_ticks((vlim[0], vlim[1]))\n# This affects all Axes as share_all = True.\ngrid.axes_llc.set(xticks=[-2, 0, 2], yticks=[-2, 0, 2])\n\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.14.7"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}