
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/axes_grid1/demo_axes_hbox_divider.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

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

        :ref:`Go to the end <sphx_glr_download_gallery_axes_grid1_demo_axes_hbox_divider.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_axes_grid1_demo_axes_hbox_divider.py:


================================
HBoxDivider and VBoxDivider demo
================================

Using an `.HBoxDivider` to arrange subplots.

Note that both Axes' location are adjusted so that they have
equal heights while maintaining their aspect ratios.

.. GENERATED FROM PYTHON SOURCE LINES 12-36

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    from mpl_toolkits.axes_grid1.axes_divider import HBoxDivider, VBoxDivider
    import mpl_toolkits.axes_grid1.axes_size as Size

    arr1 = np.arange(20).reshape((4, 5))
    arr2 = np.arange(20).reshape((5, 4))

    fig, (ax1, ax2) = plt.subplots(1, 2)
    ax1.imshow(arr1)
    ax2.imshow(arr2)

    pad = 0.5  # pad in inches
    divider = HBoxDivider(
        fig, 111,
        horizontal=[Size.AxesX(ax1), Size.Fixed(pad), Size.AxesX(ax2)],
        vertical=[Size.AxesY(ax1), Size.Scaled(1), Size.AxesY(ax2)])
    ax1.set_axes_locator(divider.new_locator(0))
    ax2.set_axes_locator(divider.new_locator(2))

    plt.show()


.. GENERATED FROM PYTHON SOURCE LINES 37-41

Using a `.VBoxDivider` to arrange subplots.

Note that both Axes' location are adjusted so that they have
equal widths while maintaining their aspect ratios.

.. GENERATED FROM PYTHON SOURCE LINES 41-55

.. code-block:: Python


    fig, (ax1, ax2) = plt.subplots(2, 1)
    ax1.imshow(arr1)
    ax2.imshow(arr2)

    divider = VBoxDivider(
        fig, 111,
        horizontal=[Size.AxesX(ax1), Size.Scaled(1), Size.AxesX(ax2)],
        vertical=[Size.AxesY(ax1), Size.Fixed(pad), Size.AxesY(ax2)])

    ax1.set_axes_locator(divider.new_locator(0))
    ax2.set_axes_locator(divider.new_locator(2))

    plt.show()


.. _sphx_glr_download_gallery_axes_grid1_demo_axes_hbox_divider.py:

.. only:: html

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

    .. container:: sphx-glr-download sphx-glr-download-jupyter

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

    .. container:: sphx-glr-download sphx-glr-download-python

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: demo_axes_hbox_divider.zip <demo_axes_hbox_divider.zip>`


.. only:: html

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

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
