

.. _sphx_glr_gallery_axes_grid1_inset_locator_demo.py:


==================
Inset Locator Demo
==================





.. image:: /gallery/axes_grid1/images/sphx_glr_inset_locator_demo_001.png
    :align: center





.. code-block:: python

    import matplotlib.pyplot as plt

    from mpl_toolkits.axes_grid1.inset_locator import inset_axes, zoomed_inset_axes
    from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar


    def add_sizebar(ax, size):
        asb = AnchoredSizeBar(ax.transData,
                              size,
                              str(size),
                              loc=8,
                              pad=0.1, borderpad=0.5, sep=5,
                              frameon=False)
        ax.add_artist(asb)


    fig, (ax, ax2) = plt.subplots(1, 2, figsize=[5.5, 3])

    # first subplot
    ax.set_aspect(1)

    axins = inset_axes(ax,
                       width="30%",  # width = 30% of parent_bbox
                       height=1.,  # height : 1 inch
                       loc=3)

    plt.xticks(visible=False)
    plt.yticks(visible=False)


    # second subplot
    ax2.set_aspect(1)

    axins = zoomed_inset_axes(ax2, zoom=0.5, loc='upper right')
    # fix the number of ticks on the inset axes
    axins.yaxis.get_major_locator().set_params(nbins=7)
    axins.xaxis.get_major_locator().set_params(nbins=7)

    plt.xticks(visible=False)
    plt.yticks(visible=False)

    add_sizebar(ax2, 0.5)
    add_sizebar(axins, 0.5)

    plt.draw()
    plt.show()

**Total running time of the script:** ( 0 minutes  0.320 seconds)



.. only :: html

 .. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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


.. only:: html

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

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