Skip to content

Plotting

Artur Tarassow edited this page May 11, 2023 · 12 revisions

Here you find everything around plotting using gretl in combination with gnuplot.

Two density plots in a single graph

To produce a kernel density plot drawing the density for two variables, you may use the following example which produces the shown plot.

set verbose off

function void double_density(series x, series d)
    /* Plots a double density plot, which compares the densities of two series
    x and d. The function first computes the kernel densities of x and d using
    the kdensity() function, then combines these two densities into a single matrix
    for plotting using GNUplot.

   :param x: A gretl series containing the first variable to be compared in the double density plot.
   :param d: A gretl series containing the second variable to be compared in the double density plot.
    */
    string s = argname(d)
    
    matrix d0 = kdensity(d ? NA : x)
    matrix d1 = kdensity(d ? x : NA)
    
    matrix dd = (d0 ~ NA) | (d1[,1] ~ NA ~ d1[,2])
    
    strings column_label = strsplit(sprintf("x %s=0 %s=1", s, s), " ")
    cnameset(dd, column_label)
    
    gnuplot 2 3 1 --matrix=dd --with-lines --output=display
end function

open australia.gdt --quiet
series dum = t < 1980:1
double_density(IAU, dum)

open mroz87.gdt --quiet
double_density(WA, LFP)

Set linewidth and dashed lines

Gnuplot offers the way to set both the linewidth as well as different types of dashes globally by a single command, respectively.

Here is the gretl plot command block where two literals were added to a simple line plot.

set verbose off
open denmark --quiet
list L = log(dataset)

plot L
    options with-lines time-series
    literal set termoption lw 2        # set linewidth globally
    # set dashtype for each series
    literal set for [i=1:8] linetype i dashtype i
end plot --output=display

This produces the following graph.

Clone this wiki locally