.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_gallery/statistics/plot_errorbar_limits_simple.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_statistics_plot_errorbar_limits_simple.f90: Error Bars: Simple Demonstration ================================ This example demonstrates how to add error bars to a plot to represent uncertainty or variability in your measurements. Error bars are essential for scientific visualization as they communicate the reliability of data. .. GENERATED FROM PYTHON SOURCE LINES 7-16 .. code-block:: Fortran program plot_errorbar_limits_simple use fplotlib, only: dp, errorbar, figure, grid, legend, savefig, title, xlabel, & ylabel implicit none integer, parameter :: n = 8 real(dp) :: x(n), y(n), yerr(n), xerr(n) integer :: i real(dp), parameter :: pi = 3.14159265358979323846_dp .. GENERATED FROM PYTHON SOURCE LINES 17-19 Create sample data with some natural variability. We'll plot measurements taken at regular intervals with both positive and negative error bounds. .. GENERATED FROM PYTHON SOURCE LINES 21-29 .. code-block:: Fortran :dedent: 1 do i = 1, n x(i) = real(i - 1, dp) y(i) = sin(x(i) / 2.0_dp) * 10.0_dp + 5.0_dp ! Symmetric errors for y-axis yerr(i) = 0.5_dp + 0.2_dp * real(i, dp) ! Symmetric errors for x-axis xerr(i) = 0.1_dp end do .. GENERATED FROM PYTHON SOURCE LINES 30-32 Plot the data with error bars on both x and y axes. The :f:subr:`errorbar` function accepts the data arrays and error magnitudes. .. GENERATED FROM PYTHON SOURCE LINES 34-37 .. code-block:: Fortran :dedent: 1 call figure(figsize=[8.0_dp, 6.0_dp]) call errorbar(x, y, yerr, xerr=xerr, fmt="o", capsize=5.0_dp, & label="measurements", color="C0") .. GENERATED FROM PYTHON SOURCE LINES 38-39 Add labels and formatting to make the plot clear and professional. .. GENERATED FROM PYTHON SOURCE LINES 40-50 .. code-block:: Fortran call xlabel("Time [s]") call ylabel("Amplitude [V]") call title("Simple Error Bar Example") call grid(.true., alpha=0.3_dp) call legend() call savefig("errorbar_limits_simple.svg") print *, "wrote errorbar_limits_simple.svg" end program plot_errorbar_limits_simple .. image-sg:: /auto_gallery/statistics/images/sphx_glr_plot_errorbar_limits_simple_001.svg :alt: plot errorbar limits simple :srcset: /auto_gallery/statistics/images/sphx_glr_plot_errorbar_limits_simple_001.svg :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none wrote errorbar_limits_simple.svg .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.029 seconds) .. _sphx_glr_download_auto_gallery_statistics_plot_errorbar_limits_simple.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_errorbar_limits_simple.f90 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_errorbar_limits_simple.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_