.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_gallery/statistics/plot_errorbar_subsample.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_subsample.f90: Error Bars: Subsampled Data =========================== This example shows how to plot error bars on a subset of data points when you have many measurements. This technique helps reduce visual clutter while still communicating uncertainty in your data. .. GENERATED FROM PYTHON SOURCE LINES 7-15 .. code-block:: Fortran program plot_errorbar_subsample use fplotlib, only: dp, errorbar, figure, grid, legend, plot, savefig, title, & xlabel, xlim, ylabel implicit none integer, parameter :: n = 100, subsample = 5 real(dp) :: x(n), y(n), yerr(n) integer :: i .. GENERATED FROM PYTHON SOURCE LINES 16-17 Generate a large dataset with measurements and their uncertainties .. GENERATED FROM PYTHON SOURCE LINES 19-25 .. code-block:: Fortran :dedent: 1 do i = 1, n x(i) = 2.0_dp * 3.14159265358979323846_dp * real(i - 1, dp) / real(n - 1, dp) y(i) = sin(x(i)) + 0.1_dp * cos(5.0_dp * x(i)) ! Error increases with x position yerr(i) = 0.1_dp + 0.05_dp * sin(x(i))**2 end do .. GENERATED FROM PYTHON SOURCE LINES 26-28 Create a figure that shows all data points as a line, but only error bars for every Nth point to reduce visual clutter .. GENERATED FROM PYTHON SOURCE LINES 30-31 .. code-block:: Fortran :dedent: 1 call figure(figsize=[10.0_dp, 6.0_dp]) .. GENERATED FROM PYTHON SOURCE LINES 32-33 Plot the full data as a thin line to show the overall trend .. GENERATED FROM PYTHON SOURCE LINES 35-36 .. code-block:: Fortran :dedent: 1 call plot(x, y, "b-", lw=1.0_dp, label="full data", alpha=0.5_dp) .. GENERATED FROM PYTHON SOURCE LINES 37-39 Overlay error bars on subsampled points to show uncertainty at specific locations. This demonstrates the data quality without cluttering the visualization. .. GENERATED FROM PYTHON SOURCE LINES 41-43 .. code-block:: Fortran :dedent: 1 call errorbar(x(1:n:subsample), y(1:n:subsample), yerr(1:n:subsample), & fmt="ro", capsize=4.0_dp, label="subsampled with errors") .. GENERATED FROM PYTHON SOURCE LINES 44-45 Add formatting and labels .. GENERATED FROM PYTHON SOURCE LINES 46-57 .. code-block:: Fortran call xlabel("Angle [radians]") call ylabel("Amplitude") call title("Error Bars on Subsampled Data") call grid(.true., alpha=0.3_dp) call legend() call xlim(0.0_dp, 2.0_dp * 3.14159265358979323846_dp) call savefig("errorbar_subsample.svg") print *, "wrote errorbar_subsample.svg" end program plot_errorbar_subsample .. image-sg:: /auto_gallery/statistics/images/sphx_glr_plot_errorbar_subsample_001.svg :alt: plot errorbar subsample :srcset: /auto_gallery/statistics/images/sphx_glr_plot_errorbar_subsample_001.svg :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none wrote errorbar_subsample.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_subsample.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_subsample.f90 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_errorbar_subsample.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_