{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n\n# Control the position and size of a colorbar with inset_locator.inset_axes\n\nThis example shows how to control the position, height, and width of colorbars\nusing `.inset_locator.inset_axes`.\n\n`.inset_locator.inset_axes` placement is controlled as for legends: either\nby providing a *loc* option (\"upper right\", \"best\", ...), or by providing a\nlocator with respect to the parent bbox.  Parameters such as *bbox_to_anchor*\nand *borderpad* likewise work in the same way, and are also demonstrated here.\n\nUsers should consider using `.Axes.inset_axes` instead (see\n`colorbar_placement`).\n\n.. redirect-from:: /gallery/axes_grid1/demo_colorbar_of_inset_axes\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\n\nfrom mpl_toolkits.axes_grid1 import inset_locator\n\nfig, (ax1, ax2) = plt.subplots(1, 2, figsize=[6, 3])\n\nim1 = ax1.imshow([[1, 2], [2, 3]])\naxins1 = inset_locator.inset_axes(\n    ax1,\n    width=\"50%\",  # width: 50% of parent_bbox width\n    height=\"5%\",  # height: 5%\n    loc=\"upper right\",\n)\naxins1.xaxis.set_ticks_position(\"bottom\")\nfig.colorbar(im1, cax=axins1, orientation=\"horizontal\", ticks=[1, 2, 3])\n\nim = ax2.imshow([[1, 2], [2, 3]])\naxins = inset_locator.inset_axes(\n    ax2,\n    width=\"5%\",  # width: 5% of parent_bbox width\n    height=\"50%\",  # height: 50%\n    loc=\"lower left\",\n    bbox_to_anchor=(1.05, 0., 1, 1),\n    bbox_transform=ax2.transAxes,\n    borderpad=0,\n)\nfig.colorbar(im, cax=axins, ticks=[1, 2, 3])\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
}