.. note::
    :class: sphx-glr-download-link-note

    Click :ref:`here <sphx_glr_download_gallery_axes_grid1_demo_colorbar_with_axes_divider.py>` to download the full example code
.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_axes_grid1_demo_colorbar_with_axes_divider.py:


===============================
Demo Colorbar with Axes Divider
===============================





.. image:: /gallery/axes_grid1/images/sphx_glr_demo_colorbar_with_axes_divider_001.png
    :class: sphx-glr-single-img





.. code-block:: python


    import matplotlib.pyplot as plt
    from mpl_toolkits.axes_grid1.axes_divider import make_axes_locatable
    from mpl_toolkits.axes_grid1.colorbar import colorbar

    fig, (ax1, ax2) = plt.subplots(1, 2)
    fig.subplots_adjust(wspace=0.5)

    im1 = ax1.imshow([[1, 2], [3, 4]])
    ax1_divider = make_axes_locatable(ax1)
    cax1 = ax1_divider.append_axes("right", size="7%", pad="2%")
    cb1 = colorbar(im1, cax=cax1)

    im2 = ax2.imshow([[1, 2], [3, 4]])
    ax2_divider = make_axes_locatable(ax2)
    cax2 = ax2_divider.append_axes("top", size="7%", pad="2%")
    cb2 = colorbar(im2, cax=cax2, orientation="horizontal")
    cax2.xaxis.set_ticks_position("top")

    plt.show()


.. _sphx_glr_download_gallery_axes_grid1_demo_colorbar_with_axes_divider.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download

     :download:`Download Python source code: demo_colorbar_with_axes_divider.py <demo_colorbar_with_axes_divider.py>`



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: demo_colorbar_with_axes_divider.ipynb <demo_colorbar_with_axes_divider.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
