Fortran Wiki
ogpf

ogpf is an object based Fortran 2003 / Fortran 2008 code implements an interface to gnuplot. A demo file, a brief tutorial and the latest version is available at: github.

Plotting Capabilities

2D Plots

  • plot(v)
  • plot(x,y)
  • plot(x,y, linespec)
  • plot(x1,y1,ls1, x2,y2,ls2, x3,y3,ls3, x4,y4,ls4)
  • plot(x, M)
  • semilogx(x,y)
  • semilogy(x,y)
  • loglog(x,y)

3D Plots

  • surf(x,y,z)
  • surf(x,y,z,lspec)
  • surf(x,y,z, palette)
  • surf(z, palette)
  • contour(x,y,z,palette)
  • contour(z,palette)

Animation

  • animation_start(delay)
  • animation_show()

Multiplot

  • multiplot(rows, cols)

Mathematical Utility Functions

  • linspace(a,b,n)
  • linspace(a,b)
  • arange(a,b,dx)
  • meshgrid(X,Y, xgv,ygv)
  • meshgrid(X,Y, xgv)

Color palette

Nine different color palettes are available. See Ann Schnider gnuplot color palettes and Gnuplotting. These color palettes can be used with:

 surf(x,y,z,palette='plt-name')
 contour(x,y,z,palette='plt-name')
  • set1
  • set2
  • set3
  • palette1
  • palette2
  • paired
  • dark2
  • accent
  • jet

The ogpf library other features

There are a plenty commands to customise the plots. This includes:

  • Plot annotation (e.g. title, xlabel, ylabel, and zlabel)
  • Axes setting (e.g. xrange, yrange, zrange, and grid)
  • Line and marker color and style
  • Gnuplot options (e.g. fonts, tics format, frame format,… )

The ogpf options command

The option command is a very powerful command and can be used to customize the gnuplot in many ways. Options can be set by calling the ogpf options. In every call, it is possible to set several options separated by semicolon or options can be set by several calls. Below shows few samples:

  • Sample 1

Set the legend (key) at the right bottom of window

call gp%options('set key bottom right')

  • Sample 2

Define a new line style

call gp%options('set style line 1 lc rgb "blue" lt 1 lw 2 pt 6 ps 1.5')

  • Sample 3

Use several options each uses separate command

call gp%options('set tics')

call gp%options('set tics font ",8"') ! font size for tics

  • Sample 4

Set several options at the same time using semicolon as delimiter

call gp%options('unset tics; unset colorbox')

Demo

There is a collection of examples in demo.f90 to show the capabilities of ogpf.

Easy to use

To use ogpf in your project, add the library file to your Fortran project (code) * ogpf.f90 (the main library)

For details see ‘demo.f90’

Important Note

To use ogpf on other operating system, you may need to modify the terminal type and fonts in the section of Configuration Parameters. A Makefile has been provided to build the demo from command line.

Example codes

This section shows selected example codes from demo.f90

  • Example 1
    SUBROUTINE Exmp01
        !...............................................................................
        !Example 1: A very basic example
        !...............................................................................
        TYPE(gpf):: gp
        INTEGER, PARAMETER:: n=17
        Real(wp):: x(n)
        Real(wp):: y(n)
        ! Input data
        x=dble([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])
        y=dble([66,51,38,27,18,11,6,3,2,3,6,11,18,27,38,51,66])

        ! Annotation: set title, xlabel, ylabel
        CALL gp%title('Example 1. A simple xy plot')
        CALL gp%xlabel('my x axis ...')
        CALL gp%ylabel('my y axis ...')
        Call gp%options('set style data linespoints')
        !Call Plot to draw a vector against a vector of data
        CALL gp%plot(x, y)
    END SUBROUTINE Exmp01

See results in github.