Skip to content

plot_hist (automatic creation)

Fabian Kindermann edited this page Apr 2, 2021 · 1 revision
subroutine plot_hist(xvalues, nbins, left, right, incl_outside, absolute, color, legend)

Description:

Our toolbox provides a set of routines that can be used for plotting graphs directly out of your Fortran program. The plotting process for 2D-graphs thereby consists of two steps. The subroutines plot and plot_hist allow to add plotdata (i.e. lines, dots and histograms) to your plots (almost as many as you want). After you’ve added all the necessary data to your plot, you can start the plotting process by means of the subroutine execplot, which will transfer your plot data to the program GNUplot and start this program, so that your graphs will be displayed in a pop-up window.

The subroutine plot_hist with automatic plot creation adds as histogram to your plot. The subroutine creates a histogram with different equally spaced bins from the data that is supplied in an array. By means of some optional input arguments, you can control the creation process of the histogram. The subroutine also contains a couple of optional plot formatting inputs.

Input arguments:

  • real*8 :: xvalues(:)
    This is a one-dimensional array of arbitrary length that contains the data for creating the histogram.
  • rinteger :: nbins
    This integer variable governs how many (equally spaced) bins should be used for creating the histogram plot.

Optional arguments:

  • real*8 :: left
    By default, the subroutine uses all data supplied in xvalues for the creation of the histogram. If this data, however, contains some extreme observations, then the lower or upper bound of the histogram may become quite large. In this case, you can supply a value for left that defines a lower bound for the creation of the histogram. If a value is supplied, then all observations below the lower bound are ignored in the histogram creation process.
  • real*8 :: right
    By default, the subroutine uses all data supplied in xvalues for the creation of the histogram. If this data, however, contains some extreme observations, then the lower or upper bound of the histogram may become quite large. In this case, you can supply a value for right that defines an upper bound for the creation of the histogram. If a value is supplied, then all observations above the upper bound are ignored in the histogram creation process.
  • logical :: incl_outside
    If a lower or an upper bound are set through the variables left or right, then the subroutine by default just ignores all data points in xvalues that lie outside of these bounds. If you however supply a value of .true. for the variable incl_outside, then the outliers will be added to the lowest or highest bin, respectively.
  • logical :: absolute
    By default the subroutine plot_hist plots relative frequencies of the data. If you, however, want it to display absolute frequencies instead, you can supply a value of .true. through this optional input variable.
  • character(LEN=*) :: color
    This character argument allows to specify the color of the line that should be drawn. You can use both literal color names like 'blue' or 'red' or hexadecimal color codes like '#0000FF' for blue or '#FF0000' for red. The internet offers multiple sources that allow you to determine the hexadecimal codes of colors. For further information about colors in GNUplot, you can look at its documentation. If no color value is specified, then the plotting routine will give each line a different color according to a predetermined color scheme.
  • character(LEN=*) :: legend
    Through this character variable of arbitrary length, you can supply a legend entry for the respective line you want to plot.

References

  • For further reading refer to:
  • This routine is used in the following programs:
    • prog02_16.f90
    • prog04_08.f90
Clone this wiki locally