.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_gallery/subplots_axes_and_figures/plot_subplots_demo.f90" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. 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_auto_gallery_subplots_axes_and_figures_plot_subplots_demo.f90: Multiple Subplots Demonstration =============================== This example shows how to create and manage multiple plots within a single figure using subplots. Subplots are essential for comparing related datasets or presenting different aspects of your analysis side by side. .. GENERATED FROM PYTHON SOURCE LINES 7-16 .. code-block:: Fortran program plot_subplots_demo use fplotlib, only: dp, figure, fill_between, grid, legend, plot, savefig, & subplot, title, xlabel, ylabel, ylim implicit none integer, parameter :: n = 200 real(dp) :: x(n), y_sin(n), y_cos(n), y_tan(n), y_exp(n) integer :: i real(dp), parameter :: pi = 3.14159265358979323846_dp .. GENERATED FROM PYTHON SOURCE LINES 17-18 Generate sample data: common trigonometric and exponential functions .. GENERATED FROM PYTHON SOURCE LINES 20-27 .. code-block:: Fortran :dedent: 1 do i = 1, n x(i) = 4.0_dp * pi * real(i - 1, dp) / real(n - 1, dp) y_sin(i) = sin(x(i)) y_cos(i) = cos(x(i)) y_tan(i) = tanh(x(i)) y_exp(i) = exp(-x(i) / (4.0_dp * pi)) * sin(x(i)) end do .. GENERATED FROM PYTHON SOURCE LINES 28-29 Create a figure with a 2x2 grid of subplots .. GENERATED FROM PYTHON SOURCE LINES 31-32 .. code-block:: Fortran :dedent: 1 call figure(figsize=[12.0_dp, 9.0_dp]) .. GENERATED FROM PYTHON SOURCE LINES 33-34 First subplot: sine function .. GENERATED FROM PYTHON SOURCE LINES 36-43 .. code-block:: Fortran :dedent: 1 call subplot(2, 2, 1) call plot(x, y_sin, "b-", lw=2.0_dp, label="sin(x)") call title("Sine Function") call xlabel("x") call ylabel("sin(x)") call grid(.true.) call legend() .. GENERATED FROM PYTHON SOURCE LINES 44-45 Second subplot: cosine function .. GENERATED FROM PYTHON SOURCE LINES 47-54 .. code-block:: Fortran :dedent: 1 call subplot(2, 2, 2) call plot(x, y_cos, "r-", lw=2.0_dp, label="cos(x)") call title("Cosine Function") call xlabel("x") call ylabel("cos(x)") call grid(.true.) call legend() .. GENERATED FROM PYTHON SOURCE LINES 55-56 Third subplot: hyperbolic tangent function .. GENERATED FROM PYTHON SOURCE LINES 58-66 .. code-block:: Fortran :dedent: 1 call subplot(2, 2, 3) call plot(x, y_tan, "g-", lw=2.0_dp, label="tanh(x)") call title("Hyperbolic Tangent") call xlabel("x") call ylabel("tanh(x)") call grid(.true.) call legend() call ylim(-1.2_dp, 1.2_dp) .. GENERATED FROM PYTHON SOURCE LINES 67-68 Fourth subplot: damped oscillation (combination of sine and exponential decay) .. GENERATED FROM PYTHON SOURCE LINES 69-82 .. code-block:: Fortran call subplot(2, 2, 4) call plot(x, y_exp, "m-", lw=2.0_dp, label="exp(-x/(4π)) * sin(x)") call fill_between(x, y_exp, color="m", alpha=0.2_dp) call title("Damped Oscillation") call xlabel("x") call ylabel("amplitude") call grid(.true.) call legend() call savefig("subplots_demo.svg") print *, "wrote subplots_demo.svg" end program plot_subplots_demo .. image-sg:: /auto_gallery/subplots_axes_and_figures/images/sphx_glr_plot_subplots_demo_001.svg :alt: plot subplots demo :srcset: /auto_gallery/subplots_axes_and_figures/images/sphx_glr_plot_subplots_demo_001.svg :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none wrote subplots_demo.svg .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.032 seconds) .. _sphx_glr_download_auto_gallery_subplots_axes_and_figures_plot_subplots_demo.f90: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Fortran source code: plot_subplots_demo.f90 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_subplots_demo.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_