{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Show RGB channels using RGBAxes\n\n`~.axes_grid1.axes_rgb.RGBAxes` creates a layout of 4 Axes for displaying RGB\nchannels: one large Axes for the RGB image and 3 smaller Axes for the R, G, B\nchannels.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\nfrom matplotlib import cbook\nfrom mpl_toolkits.axes_grid1.axes_rgb import RGBAxes, make_rgb_axes\n\n\ndef get_rgb():\n    Z = cbook.get_sample_data(\"axes_grid/bivariate_normal.npy\")\n    Z[Z < 0] = 0.\n    Z = Z / Z.max()\n\n    R = Z[:13, :13]\n    G = Z[2:, 2:]\n    B = Z[:13, 2:]\n\n    return R, G, B\n\n\ndef make_cube(r, g, b):\n    ny, nx = r.shape\n    R = np.zeros((ny, nx, 3))\n    R[:, :, 0] = r\n    G = np.zeros_like(R)\n    G[:, :, 1] = g\n    B = np.zeros_like(R)\n    B[:, :, 2] = b\n\n    RGB = R + G + B\n\n    return R, G, B, RGB\n\n\ndef demo_rgb1():\n    fig = plt.figure()\n    ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8], pad=0.0)\n    r, g, b = get_rgb()\n    ax.imshow_rgb(r, g, b)\n\n\ndef demo_rgb2():\n    fig, ax = plt.subplots()\n    ax_r, ax_g, ax_b = make_rgb_axes(ax, pad=0.02)\n\n    r, g, b = get_rgb()\n    im_r, im_g, im_b, im_rgb = make_cube(r, g, b)\n    ax.imshow(im_rgb)\n    ax_r.imshow(im_r)\n    ax_g.imshow(im_g)\n    ax_b.imshow(im_b)\n\n    for ax in fig.axes:\n        ax.tick_params(direction='in', color='w')\n        ax.spines[:].set_color(\"w\")\n\n\ndemo_rgb1()\ndemo_rgb2()\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.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}