dm_plot Module

Abstraction layer over Gnuplot.

In order to use terminal PLOT_TERMINAL_GPIC on Linux, Gnuplot must have been compiled with option gpic enabled. You can list all installed Gnuplot terminals by running:

$ gnuplot -e "set terminal"

If you build Gnuplot from source, explicitly set option --with-gpic for PIC preprocessor format, for instance:

$ ./configure --prefix=/opt --with-gpic

Example

Plot data points in SVG format to string svg:

character(len=:), allocatable :: svg
character(len=TIME_LEN)       :: ts

integer         :: i, rc
type(plot_type) :: plot
type(dp_type)   :: dps(60)

do i = 1, size(dps)
    write (ts, '("2025-01-01T00:", i0.2, ":00.000000+00:00")') i
    dps(i) = dp_type(ts, sin(i * 0.1_r8))
end do

call dm_plot_set(plot, terminal=PLOT_TERMINAL_SVG, title='Sample Plot', &
                 bidirect=.true., background='white')
rc = dm_plot_lines(plot, dps)
rc = dm_plot_read(plot, svg)
call dm_plot_close(plot)

Uses

  • module~~dm_plot~~UsesGraph module~dm_plot dm_plot iso_c_binding iso_c_binding module~dm_plot->iso_c_binding module~dm_dp dm_dp module~dm_plot->module~dm_dp module~dm_error dm_error module~dm_plot->module~dm_error module~dm_file dm_file module~dm_plot->module~dm_file module~dm_kind dm_kind module~dm_plot->module~dm_kind module~dm_pipe dm_pipe module~dm_plot->module~dm_pipe module~dm_string dm_string module~dm_plot->module~dm_string module~dm_time dm_time module~dm_plot->module~dm_time module~dm_dp->module~dm_error module~dm_dp->module~dm_kind module~dm_dp->module~dm_time module~dm_error->module~dm_kind module~dm_ascii dm_ascii module~dm_error->module~dm_ascii module~dm_file->module~dm_error module~dm_file->module~dm_kind iso_fortran_env iso_fortran_env module~dm_kind->iso_fortran_env module~dm_pipe->module~dm_error module~dm_pipe->module~dm_kind unix unix module~dm_pipe->unix module~dm_string->module~dm_error module~dm_string->module~dm_kind module~dm_time->module~dm_error module~dm_time->module~dm_kind module~dm_util dm_util module~dm_time->module~dm_util module~dm_time->unix module~dm_util->module~dm_error module~dm_util->module~dm_kind

Used by

  • module~~dm_plot~~UsedByGraph module~dm_plot dm_plot module~dm_report dm_report module~dm_report->module~dm_plot module~dmpack dmpack module~dmpack->module~dm_plot module~dmpack->module~dm_report

Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: PLOT_STYLE_NONE = 0

Invalid style.

integer, public, parameter :: PLOT_STYLE_LINES = 1

Lines.

integer, public, parameter :: PLOT_STYLE_LINESPOINTS = 2

Lines with symbols.

integer, public, parameter :: PLOT_STYLE_DOTS = 3

Dots.

integer, public, parameter :: PLOT_STYLE_POINTS = 4

Points.

integer, public, parameter :: PLOT_STYLE_LAST = 4

Never use this.

integer, public, parameter :: PLOT_TERMINAL_NONE = 0

Invalid terminal.

integer, public, parameter :: PLOT_TERMINAL_ANSI = 1

ASCII with ANSI colours (dumb).

integer, public, parameter :: PLOT_TERMINAL_ASCII = 2

ASCII (dumb).

integer, public, parameter :: PLOT_TERMINAL_GIF = 3

GIF (libgd).

integer, public, parameter :: PLOT_TERMINAL_GPIC = 4

PIC preprocessor for GNU roff.

integer, public, parameter :: PLOT_TERMINAL_PNG = 5

PNG (libgd).

integer, public, parameter :: PLOT_TERMINAL_PNGCAIRO = 6

PNG (libcairo).

integer, public, parameter :: PLOT_TERMINAL_POSTSCRIPT = 7

PNG (libcairo).

integer, public, parameter :: PLOT_TERMINAL_SIXELGD = 8

Sixel (libgd).

integer, public, parameter :: PLOT_TERMINAL_SIXELTEK = 9

Sixel (bitmap graphics).

integer, public, parameter :: PLOT_TERMINAL_SVG = 10

SVG.

integer, public, parameter :: PLOT_TERMINAL_X11 = 11

X11.

integer, public, parameter :: PLOT_TERMINAL_LAST = 11

Never use this.

integer, public, parameter :: PLOT_TERMINAL_NAME_LEN = 10

Max. terminal name length.

character(len=*), public, parameter :: PLOT_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S'

Datetime format.

character(len=*), public, parameter :: PLOT_TERMINAL_NAMES(PLOT_TERMINAL_NONE:PLOT_TERMINAL_LAST) = [character(len=PLOT_TERMINAL_NAME_LEN)::'none', 'ansi', 'ascii', 'gif', 'gpic', 'png', 'pngcairo', 'postscript', 'sixelgd', 'sixeltek', 'svg', 'x11']

Gnuplot terminal names.


Derived Types

type, public ::  plot_type

Plot context type.

Components

Type Visibility Attributes Name Initial
integer, public :: terminal = PLOT_TERMINAL_NONE

Output terminal.

integer, public :: style = PLOT_STYLE_LINES

Plot line style.

integer, public :: width = 800

Plot width [px, cm].

integer, public :: height = 300

Plot height [px, cm].

character(len=FILE_PATH_LEN), public :: output = ' '

Output file name.

character(len=8), public :: background = ' '

Background colour (optional).

character(len=8), public :: foreground = '#3b4cc0'

Foreground colour (optional).

character(len=8), public :: graph = '#ffffff'

Graph background colour.

character(len=FILE_PATH_LEN), public :: font = ' '

Font name or file path (optional).

character(len=128), public :: title = ' '

Plot title (optional).

character(len=128), public :: xlabel = ' '

X label (optional).

character(len=128), public :: ylabel = ' '

Y label (optional).

character(len=TIME_LEN), public :: xrange(2) = ' '

X axis range.

real(kind=r8), public :: yrange(2) = 0.0_r8

Y axis range.

logical, public :: bidirect = .false.

Bi-directional anonymous pipe.

logical, public :: monochrome = .false.

Black and white drawing (PostScript only).

logical, public :: persist = .false.

Persistent Gnuplot process (use only with X11).

logical, public :: xautoscale = .true.

Auto-scale X axis.

logical, public :: yautoscale = .true.

Auto-scale Y axis.

logical, public :: grid = .true.

Show grid.

logical, public :: legend = .false.

Show legend.


Functions

public function dm_plot_error(plot, output, n) result(rc)

Returns Gnuplot's standard error output in allocatable character string output. The result is an empty string of length 1 if no output to standard error has been made.

Arguments

Type IntentOptional Attributes Name
type(plot_type), intent(inout) :: plot

Plot type.

character(len=:), intent(out), allocatable :: output

Bytes returned by Gnuplot.

integer(kind=i8), intent(out), optional :: n

Bytes read.

Return Value integer

public function dm_plot_lines(plot, dps) result(rc)

Plots XY data points as line chart.

Arguments

Type IntentOptional Attributes Name
type(plot_type), intent(inout) :: plot

Plot type.

type(dp_type), intent(inout) :: dps(:)

Data points array.

Return Value integer

public function dm_plot_read(plot, output, n) result(rc)

Returns number of bytes read from Gnuplot, and plot data in n. The output is an empty string of length 1 if no bytes have been returned.

Arguments

Type IntentOptional Attributes Name
type(plot_type), intent(inout) :: plot

Plot type.

character(len=:), intent(out), allocatable :: output

Bytes returned by Gnuplot.

integer(kind=i8), intent(out), optional :: n

Bytes read.

Return Value integer

public pure elemental function dm_plot_terminal_from_name(name) result(terminal)

Returns Gnuplot terminal backend of given name.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: name

Terminal name.

Return Value integer

public pure elemental function dm_plot_terminal_is_valid(terminal) result(valid)

Returns .true. if the given terminal is valid. PLOT_TERMINAL_NONE is an invalid terminal.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: terminal

Terminal type enumerator.

Return Value logical

public function dm_plot_version(name, found) result(version)

Returns Gnuplot version as allocatable string. This function is quite slow as Gnuplot has to be started in a new process.

Arguments

Type IntentOptional Attributes Name
logical, intent(in), optional :: name

Add prefix gnuplot/.

logical, intent(out), optional :: found

Returns .true. if Gnuplot has been found.

Return Value character(len=:), allocatable

Version string.


Subroutines

public subroutine dm_plot_close(plot)

Closes pipe connected to standard error if in bidrectional mode.

Arguments

Type IntentOptional Attributes Name
type(plot_type), intent(inout) :: plot

Plot type.

public pure subroutine dm_plot_set(plot, terminal, style, width, height, output, background, foreground, graph, font, title, xlabel, ylabel, xrange, yrange, bidirect, persist, xautoscale, yautoscale, grid, legend, monochrome)

Sets plot attributes.

Arguments

Type IntentOptional Attributes Name
type(plot_type), intent(inout) :: plot

Plot type.

integer, intent(in), optional :: terminal

Output terminal.

integer, intent(in), optional :: style

Plot line style.

integer, intent(in), optional :: width

Plot width.

integer, intent(in), optional :: height

Plot height.

character(len=*), intent(in), optional :: output

Output file name.

character(len=*), intent(in), optional :: background

Background colour.

character(len=*), intent(in), optional :: foreground

Foreground colour.

character(len=*), intent(in), optional :: graph

Graph background colour.

character(len=*), intent(in), optional :: font

Font name or file path.

character(len=*), intent(in), optional :: title

Plot title.

character(len=*), intent(in), optional :: xlabel

X axis label.

character(len=*), intent(in), optional :: ylabel

Y axis label.

character(len=*), intent(in), optional :: xrange(2)

X axis range.

real(kind=r8), intent(in), optional :: yrange(2)

Y axis range.

logical, intent(in), optional :: bidirect

Bi-directional anonymous pipe.

logical, intent(in), optional :: persist

Persistent Gnuplot process (use only with X11).

logical, intent(in), optional :: xautoscale

Auto-scale X axis.

logical, intent(in), optional :: yautoscale

Auto-scale Y axis.

logical, intent(in), optional :: grid

Show grid.

logical, intent(in), optional :: legend

Show legend.

logical, intent(in), optional :: monochrome

No colour.