.. 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_damped_oscillation.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_damped_oscillation.f90: Damped oscillation, saved as SVG ================================ A first taste of the pylab-style API. Two damped sinusoids go into one figure, the decaying envelope is shaded behind them, and the result is written as SVG -- so the picture below is vector graphics, and stays sharp at any zoom level. Every example in this gallery is a plain Fortran program: it starts with ``use fplotlib, only: ...`` and ends with a ``savefig`` call. .. GENERATED FROM PYTHON SOURCE LINES 11-28 .. code-block:: Fortran program plot_damped_oscillation use fplotlib, only: axhline, dp, fill_between, grid, legend, plot, savefig, title, & xlabel, ylabel implicit none integer, parameter :: n = 400 real(dp), parameter :: t_max = 12.0_dp, decay = 0.25_dp, omega = 3.0_dp real(dp) :: t(n), envelope(n), y1(n), y2(n) integer :: i do i = 1, n t(i) = t_max*real(i - 1, dp)/real(n - 1, dp) end do envelope = exp(-decay*t) y1 = sin(omega*t)*envelope y2 = cos(omega*t)*envelope .. GENERATED FROM PYTHON SOURCE LINES 29-34 The curves are :math:`e^{-\gamma t} \sin \omega t` and :math:`e^{-\gamma t} \cos \omega t`, bounded by the envelope :math:`\pm e^{-\gamma t}`. The envelope goes first, so the curves are drawn on top of it. :f:subr:`fill_between` takes the band between two curves; ``alpha`` makes it translucent. .. GENERATED FROM PYTHON SOURCE LINES 36-42 .. code-block:: Fortran :dedent: 1 call fill_between(t, -envelope, envelope, color="gray", alpha=0.25_dp, & label="envelope") call plot(t, y1, "b-", label="sin", lw=2.0_dp) call plot(t, y2, "r--", label="cos") call axhline(0.0_dp, color="k", lw=0.8_dp) .. GENERATED FROM PYTHON SOURCE LINES 43-44 Labels, a grid and a legend, exactly as in matplotlib. .. GENERATED FROM PYTHON SOURCE LINES 46-51 .. code-block:: Fortran :dedent: 1 call title("Damped oscillation") call xlabel("time [s]") call ylabel("amplitude") call grid(.true.) call legend(loc="upper right") .. GENERATED FROM PYTHON SOURCE LINES 52-56 :f:subr:`savefig` picks the backend from the file extension. Ask for ``.svg`` and fplotlib writes SVG itself -- there is no external graphics library underneath. The same program would produce a bitmap by writing ``.png``, or print-ready output with ``.pdf`` or ``.eps``. .. GENERATED FROM PYTHON SOURCE LINES 57-61 .. code-block:: Fortran call savefig("damped_oscillation.svg") print *, "wrote damped_oscillation.svg" end program plot_damped_oscillation .. image-sg:: /auto_gallery/subplots_axes_and_figures/images/sphx_glr_plot_damped_oscillation_001.svg :alt: plot damped oscillation :srcset: /auto_gallery/subplots_axes_and_figures/images/sphx_glr_plot_damped_oscillation_001.svg :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none wrote damped_oscillation.svg .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.031 seconds) .. _sphx_glr_download_auto_gallery_subplots_axes_and_figures_plot_damped_oscillation.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_damped_oscillation.f90 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_damped_oscillation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_