

.. _sphx_glr_gallery_subplots_axes_and_figures:

.. _subplots_axes_and_figures_examples:

Subplots, axes and figures
==========================



.. raw:: html

    <div class="sphx-glr-thumbnails">

.. thumbnail-parent-div-open

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Aligning xlabel and ylabel using .Figure.align_xlabels and .Figure.align_ylabels">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_align_labels_demo_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_align_labels_demo.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Aligning Labels</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="    This example is primarily intended to show some advanced concepts in     Matplotlib.">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_auto_subplots_adjust_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_auto_subplots_adjust.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Programmatically controlling subplot adjustment</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This demo shows how to set the aspect of an Axes box directly via ~.Axes.set_box_aspect. The bo...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_axes_box_aspect_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_axes_box_aspect.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Axes box aspect</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Example use of fig.add_axes to create inset axes within the main plot axes.">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_axes_demo_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_axes_demo.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Axes Demo</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The first figure in this example shows how to zoom in and out of a plot using ~.Axes.margins in...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_axes_margins_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_axes_margins.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Controlling view limits using margins and sticky_edges</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="You can control the axis tick and grid properties">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_axes_props_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_axes_props.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Axes Props</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Axes Zoom Effect">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_axes_zoom_effect_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_axes_zoom_effect.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Axes Zoom Effect</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Create lines or rectangles that span the axes in either the horizontal or vertical direction, a...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_axhspan_demo_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_axhspan_demo.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">axhspan Demo</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="How to set and adjust plots with equal axis aspect ratios.">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_axis_equal_demo_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_axis_equal_demo.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Equal axis aspect ratio</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Choose axis label position when calling ~.Axes.set_xlabel and ~.Axes.set_ylabel as well as for ...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_axis_labels_demo_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_axis_labels_demo.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Axis Label Position</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Broken axis example, where the y-axis will have a portion cut out.">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_broken_axis_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_broken_axis.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Broken Axis</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="You can pass a .Figure subclass to .pyplot.figure if you want to change the default behavior of...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_custom_figure_class_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_custom_figure_class.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Custom Figure subclasses</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Constrained layout attempts to resize subplots in a figure so that there are no overlaps betwee...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_demo_constrained_layout_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_demo_constrained_layout.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Resizing axes with constrained layout</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="~.Figure.tight_layout attempts to resize subplots in a figure so that there are no overlaps bet...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_demo_tight_layout_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_demo_tight_layout.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Resizing axes with tight layout</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Demo of how to display two scales on the left and right y-axis.">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_fahrenheit_celsius_scales_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_fahrenheit_celsius_scales.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Different scales on the same axes</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The native figure size unit in Matplotlib is inches, deriving from print industry standards. Ho...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_figure_size_units_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_figure_size_units.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Figure size in different units</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Each axes can have a title (or actually three - one each with loc &quot;left&quot;, &quot;center&quot;, and &quot;right&quot;...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_figure_title_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_figure_title.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Figure labels: suptitle, supxlabel, supylabel</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="To create plots that share a common axis (visually) you can set the hspace between the subplots...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_ganged_plots_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_ganged_plots.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Creating adjacent subplots</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This shows 4 possible geographic projections.  Cartopy_ supports more projections.">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_geo_demo_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_geo_demo.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Geographic Projections</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Sometimes we want to combine two subplots in an axes layout created with ~.Figure.subplots.  We...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_gridspec_and_subplots_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_gridspec_and_subplots.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Combining two subplots using subplots and GridSpec</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip=".GridSpec is a flexible way to layout subplot grids.  Here is an example with a 3x3 grid, and a...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_gridspec_multicolumn_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_gridspec_multicolumn.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Using Gridspec to make multi-column/row subplot layouts</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="GridSpecs can be nested, so that a subplot from a parent GridSpec can set the position for a ne...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_gridspec_nested_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_gridspec_nested.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Nested Gridspecs</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="You can use decreasing axes by flipping the normal order of the axis limits">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_invert_axes_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_invert_axes.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Invert Axes</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="matplotlib.pyplot uses the concept of a current figure and current axes. Figures are identified...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_multiple_figs_demo_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_multiple_figs_demo.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Managing multiple figures in pyplot</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Sometimes we want a secondary axis on a plot, for instance to convert radians to degrees on the...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_secondary_axis_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_secondary_axis.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Secondary Axis</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="It&#x27;s common to make two or more plots which share an axis, e.g., two subplots with time as a co...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_share_axis_lims_views_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_share_axis_lims_views.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Sharing axis limits and views</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="You can share the x- or y-axis limits for one axis with another by passing an ~.axes.Axes insta...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_shared_axis_demo_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_shared_axis_demo.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Shared axis</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Sometimes it is desirable to have a figure with two different layouts in it. This can be achiev...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_subfigures_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_subfigures.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Figure subfigures</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Simple demo with multiple subplots.">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_subplot_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_subplot.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Multiple subplots</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Adjusting the spacing of margins and subplots using .pyplot.subplots_adjust.">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_subplots_adjust_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_subplots_adjust.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Subplots spacings and margins</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip=".pyplot.subplots creates a figure and a grid of subplots with a single call, while providing re...">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_subplots_demo_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_subplots_demo.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Creating multiple subplots using plt.subplots</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Two plots on the same axes with different left and right scales.">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_two_scales_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_two_scales.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Plots with different scales</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Example of an inset axes and a rectangle showing where the zoom is located.">

.. only:: html

  .. image:: /gallery/subplots_axes_and_figures/images/thumb/sphx_glr_zoom_inset_axes_thumb.png
    :alt:

  :ref:`sphx_glr_gallery_subplots_axes_and_figures_zoom_inset_axes.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Zoom region inset axes</div>
    </div>


.. thumbnail-parent-div-close

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /gallery/subplots_axes_and_figures/align_labels_demo
   /gallery/subplots_axes_and_figures/auto_subplots_adjust
   /gallery/subplots_axes_and_figures/axes_box_aspect
   /gallery/subplots_axes_and_figures/axes_demo
   /gallery/subplots_axes_and_figures/axes_margins
   /gallery/subplots_axes_and_figures/axes_props
   /gallery/subplots_axes_and_figures/axes_zoom_effect
   /gallery/subplots_axes_and_figures/axhspan_demo
   /gallery/subplots_axes_and_figures/axis_equal_demo
   /gallery/subplots_axes_and_figures/axis_labels_demo
   /gallery/subplots_axes_and_figures/broken_axis
   /gallery/subplots_axes_and_figures/custom_figure_class
   /gallery/subplots_axes_and_figures/demo_constrained_layout
   /gallery/subplots_axes_and_figures/demo_tight_layout
   /gallery/subplots_axes_and_figures/fahrenheit_celsius_scales
   /gallery/subplots_axes_and_figures/figure_size_units
   /gallery/subplots_axes_and_figures/figure_title
   /gallery/subplots_axes_and_figures/ganged_plots
   /gallery/subplots_axes_and_figures/geo_demo
   /gallery/subplots_axes_and_figures/gridspec_and_subplots
   /gallery/subplots_axes_and_figures/gridspec_multicolumn
   /gallery/subplots_axes_and_figures/gridspec_nested
   /gallery/subplots_axes_and_figures/invert_axes
   /gallery/subplots_axes_and_figures/multiple_figs_demo
   /gallery/subplots_axes_and_figures/secondary_axis
   /gallery/subplots_axes_and_figures/share_axis_lims_views
   /gallery/subplots_axes_and_figures/shared_axis_demo
   /gallery/subplots_axes_and_figures/subfigures
   /gallery/subplots_axes_and_figures/subplot
   /gallery/subplots_axes_and_figures/subplots_adjust
   /gallery/subplots_axes_and_figures/subplots_demo
   /gallery/subplots_axes_and_figures/two_scales
   /gallery/subplots_axes_and_figures/zoom_inset_axes

