<< Click to Display Table of Contents >>

Navigation:  Gekko commands >


Previous pageReturn to chapter overviewNext page

Gekko uses gnuplot 5.1 internally for plotting. The gnuplot engine may crash if fed with illegal syntax or nonsensical data. Unfortunately, the gnuplot error messages seem hard to extract into Gekko, but you may use PLOT<dump> and feed the file into gnuplot 5.1 to inspect the error messages.


You can create plots of variables with the PLOT command, see demo graphs. The PLOT arguments have the same syntax as PRT/MULPRT, SHEET and CLIP. You can store plot options/settings in external .gpt files, so that you can easily reuse the styling. PLOT uses the free open-source gnuplot 5.1 internally, and the settings/options of the PLOT command and corresponding .gpt files are named to match gnuplot naming conventions. PLOT can create an .emf, .svg, .png or .pdf file silently, if the FILE= option is used. The .emf files are practical for MS Office applications, including Word. The .svg format is practical for html pages, and should usually be preferred over .png for such pages. Gnuplot supports many output file formats (so-called 'terminals'), so more formats may be added if needed.


You may use <bank=... ref=...> to locally change the databanks used, instead of using OPEN and CLOSE.


Note: You may use the in-built XML Notepad editor to edit the .gpt files, cf. the XEDIT command. You can use a global .gpt file via "OPTION plot using = ... ;".


Note that Gekko 3.0 supports plotting (and printing) series with mixed frequencies.


PLOT uses the same internal component as PRT, so regarding operators and other details, also see the PRT help page.






PLOT <period  operator   PLOTCODE=...  DUMP NOMAX mainOptions  BANK=...  REF=... MISSING=...>  elements   USING=...  FILE=... ;
 elements: element1, element2, ...
 element: expression  label <elementOptions>


If no period is given inside the <...> angle brackets, the global period is used (cf. TIME).

If a variable without databank indication is not found in the first-position databank, Gekko will look for it in other open databanks if databank search is active (cf. MODE).

The more general options shown above are the following (cf. the 'Main options' table below for all the plot-related options):



(Optional). Local period, for instance 2010 2020, 2010q1 2020q4 or %per1 %per2+1.


(Optional). 'Long': abs, dif, pch, gdif, or 'short': n, d, p, dp, m, q, mp, r, rd, rp, rdp


Name of the variable(s) printed. Several variables can be printed at once using var1, var2, var3, .... You may also use lists or expressions.


(Optional). The contents of this string must be gnuplot code (for instance 'set' commands separated by semicolon), and the contents is sent to gnuplot and inserted just before the gnuplot 'plot' statement.


(Optional). With option <dump>, Gekko will put two gnuplot files in the working folder: (the gnuplot script), and (the gnuplot data). The gnuplot script can be run inside gnuplot 5.1 with the following command: load '' (note the quotes).


(Optional). Do not restrict the number of curves, cf. OPTION plot elements max.


(Optional). A bankname where variables are looked up. For instance PLOT <bank = b1> x; is equivalent to PLOTb1:x;. See also <REF = ...>. These options can be convenient instead of opening and closing banks.


(Optional). A bankname where reference variables are looked up. For instance PLOT <bank = b1 ref = b2 m> x; uses banks b1 and b2 for the multiplier. See also <BANK = ...>. These options can be convenient instead of opening and closing banks


(Optional). With <missing = ignore>, PLOT will deal with missing array subseries and missing data values like GAMS, treating them as zero for sums and mathematical expressions, or skipping the printing of a subseries if it does not exist. The following options are set locally and reverted afterwards: option series array print missing = skip; option series array calc missing = zero; option series data missing = zero. See also the appendix page on missings.


(Optional). Indicates a .gpt file (xml template) to style your plot. You may use '*' as filename to select from .gpt files in the working folder. If no extension is provided, .gpt is added automatically. See also OPTION plot using = ... .

Filenames may be contain an absolute path like c:\projects\gekko\myfile, a relative path like \gekko\myfile.gbk, or be stated without a path. Filenames containing blanks and special characters should be put inside quotes. See more on filenames here.


(Optional).  Use extension emf (default), png, svg or pdf.

The resulting file is in .emf format as default. Such a file can be imported into many Windows programs such as Word and others. You may use a filename with explicit extension .png/.svg/.pdf instead, and PLOT will produce the file in that format. The .svg files are very useful for insertion into html document.

Filenames may be contain an absolute path like c:\projects\gekko\myfile, a relative path like \gekko\myfile.gbk, or be stated without a path. Filenames containing blanks and special characters should be put inside quotes. See more on filenames here.



You may use an operator to indicate which kind of data transformation you would like on your variables, for instance PLOT<d>, PLOT<q>, PLOT<pch>. As in the PRT command, you may also use element-specific operators (for instance PLOT unemp, gdp<p>;).  See the PRT command regarding the use of operators.


In addition to the above options, you may put graph-options inside either the main option field (PLOT <...>), or inside the element option fields (PLOT x1<...>, x2<...>). These options can alternatively be stored in an external xml-based .gpt file, for instance PLOT x1, x2 using=p; will use the file p.gpt to style the graph. The structure of the .gpt file corresponds to the distinction between PLOT main options and element options. Cf. the example section below.


Main options


Located inside the PLOT<...> option field, or in .gpt files directly inside the <gekkoplot> tag. The first column of the table is before the '=', and the second column of the table is after, for instance PLOT <type = linespoints>;. Some of the right-hand side expressions may require quotes around them, for instance PLOT<font = 'Verdana'>;, not PLOT<font = Verdana>;. If in doubt, try using quotes.



The most used of the following are the line-types linespoints and lines, together with boxes (column chart).


linespoints, lines: Normal lines, with or without point markers.

boxes: bar chart/histogram. If several timeseries are boxes, these will be clustered, unless the stacked option is set.

filledcurves: lines where the area below each line is an area. If the stacked option is set, the areas are stacked instead of overlayed.

steps: Step-wise lines, a bit box-like.

points: Just the point markers, no lines.

dots: Just tiny dots.

impulses: vertical lines instead of boxes.


Quotes may be omitted.


'1':normal, '2':dashed, '3':dotted, ... (default: '1'). More. Quotes should be used.


A number. Default: 3.


You may use named colors (for instance 'red') or color codes known from html (for instance '#0000FF'). Default: color is taken from the palette setting. Quotes should be used.


An integer. These points are shown for each period, if the linetype is linespoints or points.






... etc.


Default: 7 (circle). More.


A number. The size of the points. Default: 0.5.


String. Only relevant for linetype boxes. You may use many combinations, for instance 'empty', 'solid', 'solid 0.5' (50% transparent), 'solid border', 'pattern 0', 'pattern 1', etc. To provide a black border around the boxes, use for instance 'solid 1.0 border linetype -1'. Default: 'solid'. More. Quotes should be used.


The title of the entire plot. Quotes should be used.


A subtitle underneath the title. Quotes should be used.


Set for instance 'Verdana', 'Arial', 'Times', 'Courier New' ... . Default is 'Verdana'. Quotes should be used.


Default is 12.


Use this option to indicate bold font type for different elements. Choose from 'title', 'ytitle', 'xtics', 'ytics', 'key', or indicate several of these separated with commas, for instance 'title, ytitle, key'. Quotes should be used.


Use this option to indicate italic font type for different elements. Choose from 'title', 'ytitle', 'xtics', 'ytics', 'key', or indicate several of these separated with commas, for instance 'title, ytitle, key'. Quotes should be used.


You may choose between 'in' or 'out'. Default: 'out'. Quotes should be used. Regarding number formatting, see OPTION plot decimalseparator = ....


Choose between yes|no|xline|yline. If yes, both vertical and horizontal lines are shown. If xline, only vertical lines are shown. If yline, only horizontal lines are shown. Default: yes. Quotes can be omitted.


This sets how gridlines are formatted, stated in gnuplot syntax. Quotes should be used.


Default is the following, which are light grey dashed lines: 'linecolor rgb "#d3d3d3" dashtype 3 linewidth 1.5'.

The gridstyle 'linecolor black dashtype 2 linewidth 2.0' will provide black dashed lines which look ok in Word.

To emulate the solid grey style of Gekko 2.2.4 and earlier, use 'linecolor rgb "#f0f0f0" linetype 1 linewidth 1'.


In general, the same dashed lines can look quite different in different "environments". So there may be differences in the Gekko window versus inside Word versus pdf (exported from Word) versus html (via svg) versus pdf (exported from html) versus printed from Word or a browser. In general, there will be small differences between the .emf, .svg, .png and .pdf files. For html pages, please use .svg instead of .png for better quality.


In gnuplot, the legend is called 'key'. This sets how the legend is to be displayed, stated in gnuplot syntax. Default is the following, which is outside of the plot area, at the bottom center: 'out horiz bot center Left reverse'. Quotes should be used.


To remove the key completely, you can use gnuplot-code 'set key off': PLOT<plotcode='set key off'>;.


You may use a comma-separated list of named colors (for instance: "red, blue, green", or rgb color codes (like "#0000FF, #FFFF00, #00FFFF"). Default is this: "red, web-green, web-blue, orange, dark-blue, magenta, brown4, dark-violet, grey50, black" (these are gnuplot internal color names). More. Quotes should be used.


If the element is set active (<stack>), boxes are stacked instead of clustered, and filledcurves are stacked instead of overlayed. Default: no.


The width of the boxes. Set to 1 for max width. Default: 0.75.


The gap between clusters of boxes (only relevant if you are using two or more boxes at the same time). Default: 2, that is, a gap of what two boxes would fill.


With the separate option, lines and boxes are separated, so that all lines (non-boxes) are shown at the top of the plot (with labels on the left y axis), whereas all boxes are shown at the bottom of the plot (with labels on the right y2 axis). For instance, this is practical for residual plots, so that the residuals do not interfere with observed/fitted lines. The option will override any y2 options regarding the lines. This functionality is Gekko-specific and does not yet work for stacked boxes (option boxstack), where the scaling will not be precise (this will be fixed in a future version). Default: no.


Vertical line at the given period. Several lines may be given. For instance: <xline>2020q2</xline>.


Vertical line between the given period and the period before. Several lines may be given. For instance: <xlinebefore>2020q2</xlinebefore>.


Vertical line between the given period and the period after. Several lines may be given. <xlineafter>2020q2</xlineafter>



The xzeroaxis is the horiontal axis corresponding to y=0, and the x2zeroaxis is the axis corresponding to y2=0 (the right-hand side y-axis). These xzeroaxes will only be shown if the y or y2 values change sign. Default for xzeroaxis is yes, and default for x2zeroaxis is no.


Mirror the left y axis on the right side. You may choose between '0':none, '1':only tics, '2':tics with labels, and '3': tics with labels + axis label. If the y2 axis is used, the ymirror setting is ignored.



A title for the y or y2 axis. Quotes should be used. If the title should break, you may use a '\n', for instance PLOT<ytitle='Balance\nof payments'>;.



Horizontal line at the given y- or y2-value. Several lines may be given. For instance: <yline>150</yline>. The lines are not shown if the lines are outside of the y values of the variables shown in the graph (you may combined with ymaxsoft/yminsoft).


You may alternatively do horizontal lines manually, for instance: PLOT 150 '' <type=lines dashtype='3' linecolor='gray'>, x1, x2, x3;. The quotes '' after 150 indicated that the label is skipped. Putting the line first means that it will appear in the background (looks better for type=boxes).




Fixed max for the y or y2 values. Will overrule any maxhard or maxsoft values. Can cut off data points.



All values > maxhard are filtered out, but all values < maxhard are shown. This setting is practical for filtering out outliers. Think of 'hard' as being capable of cutting off data points.



All values are shown, but the axis will not scale down below ymaxsoft. This keeps a sensible scale, even if the y or y2 values are very small.  Think of 'soft' as being incapable of cutting off any data points.



Fixed min for the y or y2 values. Will overrule any minhard or minsoft values. Can cut off data points.



All values < minhard are filtered out, but all values > minhard are shown.This setting is practical for filtering out outliers. Think of 'hard' as being capable of cutting off data points.



All values are shown, but the axis will not scale up above yminsoft. This keeps a sensible scale, even if the y or y2 values are very small. Think of 'soft' as being incapable of cutting off any data points.


A free-floating label is inserted at the given position. Several labels may be given. Quotes should be used. [Not available yet]


An arrow is inserted between the given positions. Several arrows may be given. [Not available yet]




Element options


Located in the element options, for instance PLOT x1<...>, x2<...>, or in .gpt files inside the <lines> tag (which contains <line> tags).



See under the main options.


See under the main options.


See under the main options.


See under the main options.


See under the main options.


See under the main options.


See under the main options.


Set y2 to indicate the you want the series shown at the y2 axis (right-hand y axis).





Example using PLOT options versus gpt file


For instance, you may produce a graph with dashed lines using this:


PLOT <type=lines linecolor='blue'> rfy<dashtype='1'>, rfcp<dashtype='2'>, rfm<dashtype='3'>, rfe<dashtype='4'>;


Here, in the main option field, the linetype is stated (type=lines), including the linecolor (color='blue'). These can also be stated individually in the elements options, if needed. In the element options, four dashtypes are given, for instance dashtype = '1'.


Instead of the above PLOT statement, you may use:


PLOT rfy, rfcp, rfm, rfe using=p;


together with the following .gpt file (xml):




As you can see, the structure in the first PLOT statement corresponds to the structure of the .gpt file. You may also combine PLOT options and gpt files: in that case, the PLOT options will override the gpt options. So for instance, PLOT rfy, rfcp, rfm<color='red'>, rfe using=p; would make the third line red instead of blue.




Other examples


The command


PLOT <p> x1, x2;


plots percentage growth of the timeseries x1 and x2 from the first-position databank.


FOR %= fY, fX, fE;
  PLOT {%i} file=graph_{%i};


This creates three graphs that are put into three different .emf files.


You may 'piggyback' gnuplot code along with the PLOT command, for instance:


PLOT <plotcode = 'set xtics rotate by 90'> fy, fe, fcp;


This rotates the x-tic labels. If you need to state several gnuplot statements, you can separate them with ';'.



Age profiles


A special kind of plot shows the population of part of the population in age groups. If the annual array-series p!a is defined for different age-groups, for instance p[30] for 30-year olds, this array-series can be transformed via the rotate() function into another array-series p!u defined over the special 'undated' (u) frequency (now defined for different years like p!u[2020]).


= series(1);  //definition of p!a
time 2010 2010;
time 2020 2020;
time 2010 2020;
prt <n> p;
option freq u; //undated
time 1u 99u;
= rotate(p!a, 1); //definition of p!u
#= 2010, 2020; #= #t.strings();
plot p[#t];


This produces the following plot, with the age dimension on the x-axis.






Plot file editor


At the moment, Gekko uses xml files to store the plot settings. In the longer run, another format might be chosen, and an graphical  interface to change these settings might be provided.


Until then, it is recommended that you use the in-built XML Notepad editor to edit the XML files, cf. the XEDIT command (if used, choose 'View' --> 'Expand All' to unfold all XML nodes). You may also use Notepad (cf. the EDIT command), but it is recommended to use a specific XML editor for editing the tables. Using a simple text editor like Notepad entails some potential problems; there will be no check that the XML syntax is correct. Also, the XML syntax represents some characters in a special way: notably the '<' , '>', and '&' characters (these should be written '&lt;', '&gt;', and '&amp;').


If the file is not in valid XML syntax, Gekko will complain that the file is invalid and abort.






PLOT produces a graph by means of the open-source program gnuplot as an underlying engine. You do not need to install anything in order to use PLOT (the Gekko installation files contain gnuplot).


In the graph window, you may change the so-called operators by clicking on the radio buttons (or multiplier checkbox). This way, you can quickly change to for instance percentage growth rate etc. You may copy-paste the graph to e.g. a word-processor like Word by clicking the ‘Copy’ button. There are also options to save the graph as a emf/svg/png/pdf files.


You may close the PLOT graph window by pressing the 'Esc' button.


Per default, PLOT will place annual and undated data at the x-tics, and quarterly and monthly data between x-tics. See OPTION plot xlabels ... options, also if you prefer to use 15, 16, 17 etc., instead of 2015, 2016, 2017, etc.


Please note that the same graph may look different in different "environments". The Gekko graph window shows an .emf file, and the same .emf file may look a bit different when imported into Word (or converted to pdf or printed from Word). Also, a .svg version of the graph may look different in html. The differences apply to, for instance, dashed lines and fonts. Both .emf, .svg and .pdf are vector formats, whereas .png is a raster format (bitmap).


See the rotate() function if you need to plot for instance age profiles of array-series that are defined in the age dimension.


Planned enhancements:


Stacked curves and histograms shown as shares (summing to 1 or 100), perhaps using operator <s> for shares.

Indexed data, for instance showing all lines as index 2015=1, perhaps using operator <i> for index.

Options <a>, <ad>, and <ap> For instance, "PLOT<a>x1, x2;" would be the same as "PLOT x1, @x1, x2, @x2;", showing values from the Reference databank.




Free-floating labels and arrows.

Outputting in more file formats like latex, etc.

It is the intention to make it possible to use R (using its plot function) as the graphing engine, too. Outputting R code instead of gnuplot code would not be too difficult. But gnuplot works ok, and is a small program that can be easily bundled with the Gekko package.




Related options


OPTION plot decimalseparator = period; [comma|period]

OPTION plot lines points = yes; [yes|no]

OPTION plot new = yes; [yes|no]

OPTION plot using = [filename];

OPTION plot xlabels annual = at; [at|between]

OPTION plot xlabels nonannual = between; [at|between]

OPTION plot xlabels digits = 4; [2|4]




Related commands