.. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_axes_grid1_demo_colorbar_of_inset_axes.py: =========================== Demo Colorbar of Inset Axes =========================== .. image:: /gallery/axes_grid1/images/sphx_glr_demo_colorbar_of_inset_axes_001.png :alt: demo colorbar of inset axes :class: sphx-glr-single-img .. code-block:: default from matplotlib import cbook import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1.inset_locator import inset_axes, zoomed_inset_axes fig, ax = plt.subplots(figsize=[5, 4]) Z = cbook.get_sample_data("axes_grid/bivariate_normal.npy", np_load=True) extent = (-3, 4, -4, 3) ax.set(aspect=1, xlim=(-15, 15), ylim=(-20, 5)) axins = zoomed_inset_axes(ax, zoom=2, loc='upper left') im = axins.imshow(Z, extent=extent, origin="lower") plt.xticks(visible=False) plt.yticks(visible=False) # colorbar cax = inset_axes(axins, width="5%", # width = 10% of parent_bbox width height="100%", # height : 50% loc='lower left', bbox_to_anchor=(1.05, 0., 1, 1), bbox_transform=axins.transAxes, borderpad=0, ) fig.colorbar(im, cax=cax) plt.show() .. _sphx_glr_download_gallery_axes_grid1_demo_colorbar_of_inset_axes.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_colorbar_of_inset_axes.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_colorbar_of_inset_axes.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature Keywords: matplotlib code example, codex, python plot, pyplot `Gallery generated by Sphinx-Gallery `_