.. 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_subplots_axes_and_figures_subplots_adjust.py: =============== Subplots Adjust =============== Adjusting the spacing of margins and subplots using :func:`~matplotlib.pyplot.subplots_adjust`. .. image:: /gallery/subplots_axes_and_figures/images/sphx_glr_subplots_adjust_001.png :class: sphx-glr-single-img .. code-block:: python import matplotlib.pyplot as plt import numpy as np # Fixing random state for reproducibility np.random.seed(19680801) plt.subplot(211) plt.imshow(np.random.random((100, 100)), cmap=plt.cm.BuPu_r) plt.subplot(212) plt.imshow(np.random.random((100, 100)), cmap=plt.cm.BuPu_r) plt.subplots_adjust(bottom=0.1, right=0.8, top=0.9) cax = plt.axes([0.85, 0.1, 0.075, 0.8]) plt.colorbar(cax=cax) plt.show() .. _sphx_glr_download_gallery_subplots_axes_and_figures_subplots_adjust.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: subplots_adjust.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: subplots_adjust.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature Keywords: matplotlib code example, codex, python plot, pyplot `Gallery generated by Sphinx-Gallery `_