.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/subplots_axes_and_figures/multiple_figs_demo.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_subplots_axes_and_figures_multiple_figs_demo.py: =================================== Managing multiple figures in pyplot =================================== `matplotlib.pyplot` uses the concept of a *current figure* and *current axes*. Figures are identified via a figure number that is passed to `~.pyplot.figure`. The figure with the given number is set as *current figure*. Additionally, if no figure with the number exists, a new one is created. .. note:: We discourage working with multiple figures through the implicit pyplot interface because managing the *current figure* is cumbersome and error-prone. Instead, we recommend using the explicit approach and call methods on Figure and Axes instances. See :ref:`api_interfaces` for an explanation of the trade-offs between the implicit and explicit interfaces. .. GENERATED FROM PYTHON SOURCE LINES 20-27 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np t = np.arange(0.0, 2.0, 0.01) s1 = np.sin(2*np.pi*t) s2 = np.sin(4*np.pi*t) .. GENERATED FROM PYTHON SOURCE LINES 28-29 Create figure 1 .. GENERATED FROM PYTHON SOURCE LINES 29-36 .. code-block:: Python plt.figure(1) plt.subplot(211) plt.plot(t, s1) plt.subplot(212) plt.plot(t, 2*s1) .. image-sg:: /gallery/subplots_axes_and_figures/images/sphx_glr_multiple_figs_demo_001.png :alt: multiple figs demo :srcset: /gallery/subplots_axes_and_figures/images/sphx_glr_multiple_figs_demo_001.png, /gallery/subplots_axes_and_figures/images/sphx_glr_multiple_figs_demo_001_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 37-38 Create figure 2 .. GENERATED FROM PYTHON SOURCE LINES 38-42 .. code-block:: Python plt.figure(2) plt.plot(t, s2) .. image-sg:: /gallery/subplots_axes_and_figures/images/sphx_glr_multiple_figs_demo_002.png :alt: multiple figs demo :srcset: /gallery/subplots_axes_and_figures/images/sphx_glr_multiple_figs_demo_002.png, /gallery/subplots_axes_and_figures/images/sphx_glr_multiple_figs_demo_002_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 43-44 Now switch back to figure 1 and make some changes .. GENERATED FROM PYTHON SOURCE LINES 44-52 .. code-block:: Python plt.figure(1) plt.subplot(211) plt.plot(t, s2, 's') ax = plt.gca() ax.set_xticklabels([]) plt.show() .. image-sg:: /gallery/subplots_axes_and_figures/images/sphx_glr_multiple_figs_demo_003.png :alt: multiple figs demo :srcset: /gallery/subplots_axes_and_figures/images/sphx_glr_multiple_figs_demo_003.png, /gallery/subplots_axes_and_figures/images/sphx_glr_multiple_figs_demo_003_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.044 seconds) .. _sphx_glr_download_gallery_subplots_axes_and_figures_multiple_figs_demo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: multiple_figs_demo.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: multiple_figs_demo.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_