.. 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_axes_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_axes_demo.f90: Axes Demo: Controlling Axes Properties ====================================== This example demonstrates how to control and customize the axes in your plots, including setting limits, adjusting aspect ratios, and using different coordinate systems. .. GENERATED FROM PYTHON SOURCE LINES 7-16 .. code-block:: Fortran program plot_axes_demo use fplotlib, only: axis, dp, figure, grid, legend, plot, savefig, set_yscale, & subplot, title, xlabel, xlim, ylabel, ylim implicit none integer, parameter :: n = 100 real(dp) :: x(n), y1(n), y2(n), y3(n) integer :: i real(dp), parameter :: pi = 3.14159265358979323846_dp .. GENERATED FROM PYTHON SOURCE LINES 17-18 Generate sample data .. GENERATED FROM PYTHON SOURCE LINES 20-26 .. code-block:: Fortran :dedent: 1 do i = 1, n x(i) = real(i - 1, dp) / real(n - 1, dp) * 2.0_dp * pi y1(i) = sin(x(i)) y2(i) = cos(x(i)) y3(i) = sin(2.0_dp * x(i)) * cos(3.0_dp * x(i)) end do .. GENERATED FROM PYTHON SOURCE LINES 27-28 Create a figure with multiple subplots demonstrating different axes configurations .. GENERATED FROM PYTHON SOURCE LINES 30-31 .. code-block:: Fortran :dedent: 1 call figure(figsize=[14.0_dp, 10.0_dp]) .. GENERATED FROM PYTHON SOURCE LINES 32-33 Subplot 1: Default axes .. GENERATED FROM PYTHON SOURCE LINES 35-41 .. code-block:: Fortran :dedent: 1 call subplot(2, 3, 1) call plot(x, y1, "b-", lw=2.0_dp) call title("Default Axes") call xlabel("x") call ylabel("sin(x)") call grid(.true., alpha=0.3_dp) .. GENERATED FROM PYTHON SOURCE LINES 42-43 Subplot 2: Custom axis limits .. GENERATED FROM PYTHON SOURCE LINES 45-53 .. code-block:: Fortran :dedent: 1 call subplot(2, 3, 2) call plot(x, y1, "r-", lw=2.0_dp) call xlim(0.0_dp, pi) call ylim(-0.5_dp, 1.0_dp) call title("Custom Limits: xlim(0,π), ylim(-0.5,1)") call xlabel("x") call ylabel("sin(x)") call grid(.true., alpha=0.3_dp) .. GENERATED FROM PYTHON SOURCE LINES 54-55 Subplot 3: Aspect ratio control (equal spacing) .. GENERATED FROM PYTHON SOURCE LINES 57-64 .. code-block:: Fortran :dedent: 1 call subplot(2, 3, 3) call plot(x, y1, "g-", lw=2.0_dp) call title("Equal Aspect Ratio") call xlabel("x") call ylabel("sin(x)") call grid(.true., alpha=0.3_dp) call axis("equal") .. GENERATED FROM PYTHON SOURCE LINES 65-66 Subplot 4: Logarithmic scale on y-axis .. GENERATED FROM PYTHON SOURCE LINES 68-82 .. code-block:: Fortran :dedent: 1 call subplot(2, 3, 4) block real(dp) :: y_positive(n) integer :: j do j = 1, n y_positive(j) = abs(y3(j)) + 0.1_dp end do call plot(x, y_positive, "m-", lw=2.0_dp) call set_yscale("log") end block call title("Logarithmic Y-Axis") call xlabel("x") call ylabel("log(|sin(2x)cos(3x)| + 0.1)") call grid(.true., alpha=0.3_dp) .. GENERATED FROM PYTHON SOURCE LINES 83-84 Subplot 5: Tight layout - axes with no padding .. GENERATED FROM PYTHON SOURCE LINES 86-93 .. code-block:: Fortran :dedent: 1 call subplot(2, 3, 5) call plot(x, y2, "c-", lw=2.0_dp) call title("Tight Layout") call xlabel("x") call ylabel("cos(x)") call grid(.true., alpha=0.3_dp) call axis("tight") .. GENERATED FROM PYTHON SOURCE LINES 94-95 Subplot 6: Multiple curves with different scales .. GENERATED FROM PYTHON SOURCE LINES 97-106 .. code-block:: Fortran :dedent: 1 call subplot(2, 3, 6) call plot(x, y1, "b-", lw=2.0_dp, label="sin(x)") call plot(x, y2, "r--", lw=2.0_dp, label="cos(x)") call plot(x, y3 * 0.5_dp, "g:", lw=2.0_dp, label="0.5*sin(2x)cos(3x)") call title("Multiple Curves") call xlabel("x") call ylabel("amplitude") call grid(.true., alpha=0.3_dp) call legend(loc="upper right") .. GENERATED FROM PYTHON SOURCE LINES 107-108 Save the figure .. GENERATED FROM PYTHON SOURCE LINES 109-113 .. code-block:: Fortran call savefig("axes_demo.svg") print *, "wrote axes_demo.svg" end program plot_axes_demo .. image-sg:: /auto_gallery/subplots_axes_and_figures/images/sphx_glr_plot_axes_demo_001.svg :alt: plot axes demo :srcset: /auto_gallery/subplots_axes_and_figures/images/sphx_glr_plot_axes_demo_001.svg :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none wrote axes_demo.svg .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.033 seconds) .. _sphx_glr_download_auto_gallery_subplots_axes_and_figures_plot_axes_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_axes_demo.f90 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_axes_demo.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_