Skip to content
Uwe Schneider edited this page Aug 5, 2022 · 70 revisions

Welcome to the gnuplotxyz wiki!

GNUPLOTXYZ.GMS

A Windows based GAMS Interface to GNUPLOT

Uwe A. Schneider


Other GAMS interfaces

GAMS2Gnuplot GAMS2Shademap GAMS2Powerpoint GAMS2GAMS GAMS Memory

Credits

This software interface was largely developed by Uwe Schneider . Credit goes also to Bruce McCarl who initiated the project in 1997 and did some initial programming and to Thomas Rutherford. Tom's existing gnuplot interface provided useful guidance. Additional contributions were made by Michael Bussieck and Armin Pruessner from GAMS Development Corporation. Thanks also to Hans-Bernhard Broeker from the Gnuplot team.

There is (almost) no technical support. Bug reports/fixes are welcome.

(Home 2D Plots 3D Plots Multi-Plots Spiderplots Examples Options)

Description

Gnuplotxyz.gms allows users to plot data from GAMS runs in GNUPLOT.

Gnuplotxyz.gms is user friendly as only one single line is needed to produce a plot. Nevertheless, many of the default options can be changed by using optional statements as illustrated below. In addition, one can modify the gnuplotxyz.gms file for personal needs and preferences.

(Home 2D Plots 3D Plots Multi-Plots Spiderplots Examples Options)

Download and Installation

  1. Download and install the latest version of gnuplot for windows from http://www.gnuplot.info/download.html. To plot spiderplots, download at least gnuplot 5.4. this version is currently available as test version. When installing make sure that the option "Add application directory to your PATH environment variable" is selected. (see below)

  1. Copy the file gnuplotxyz.gms to the .\inclib subdirectory of your GAMS system directory.

(Home 2D Plots 3D Plots Multi-Plots Spiderplots Examples Options)

Syntax

2D Plots

Note, depending on how many data columns will be provided, gnuplot may use different calculations (see errorlines, errorbars)

2D Line and other plots (no histograms)

The data to be graphed as 2D-plot must be contained in a three-dimensional parameter, i.e. a parameter which has three indexes. The elements in the first argument determine different lines in a plot. The elements in the second argument determine the points of each line. The order of elements in the second index determines how the different data points pertaining to one line are connected. The remaining argument (third index) must contain at least two elements of which one depicts the x-axis and another one the y-axis. If you choose styles with error bars you may need to give additional values (see examples).

Required syntax

$libinclude gnuplotxyz <parameter name> <xaxis element> <yaxis element>

multiple plots in sequence with custom formatting

[$setglobal < global variable name> < value>]

[$setglobal < global variable name> <value>]

$libinclude gnuplotxyz < parameter name> <xaxis element> <yaxis element>

[$setglobal < global variable name> <value>]

[$libinclude gnuplotxyz < parameter name> <xaxis element> <yaxis element>]

2D histograms using 2 indexes

Applies automatically to parameters with 2 indexes. Only use one argument after $libinclude gnuplotxyz

[$setglobal gp_hist "clustered gap 2"]

[$setglobal gp_hist "rowstacked"]

[$setglobal gp_hist "columnstacked"]

$libinclude gnuplotxyz < parameter name>

2D new histograms using 3 indexes

Applies automatically to parameters with 3 indexes and one argument after $libinclude gnuplotxyz. If each index contains rather many elements than the plot will not look nice.

$libinclude gnuplotxyz <parameter name>

xerrorlines, xerrorbars

$setglobal gp_style " xerrorlines"

$libinclude gnuplotxyz <parameter name> <xvalue> <yvalue> <xdelta>

or

$libinclude gnuplotxyz <parameter name> <xvalue> <yvalue> <xlowvalue> <xhighvalue>

yerrorlines, yerrorbars

$setglobal gp_style "yerrorbars"

$libinclude gnuplotxyz <parameter name> <xvalue> <yvalue> <ydelta>

or

$libinclude gnuplotxyz <parameter name> <xvalue> <yvalue> <ylowvalue> <yhighvalue>

candlesticks (Note: low value <opening value <closing value <high value)

$setglobal gp_style "candlesticks"

$libinclude gnuplotxyz <parameter name> <xvalue> <opening value> <low value> <high value> <closing value>

xyerrorlines,xyerrorbars

$setglobal gp_style " xyerrorlines"

$libinclude gnuplotxyz <parameter name> <xvalue> <yvalue> <xdelta> <ydelta>

or

$libinclude gnuplotxyz <parameter name> <xvalue> <yvalue> <xlowvalue> <xhighvalue> <ylowvalue> <yhighvalue>

2D - Loop

Outside (above) loops:

$libinclude gnuplotxyz

[$setglobal gp_loop1 <setname1>]

[$setglobal gp_loop2 <setname2>]

[$setglobal gp_loop3 <setname3>]

[$setglobal gp_loop4 <setname4>]

The statements in square brackets above are optional. If used, the title of the graph will show the current element of the loop. You can "unset" the values of these variables by assigning "no" or "0" (see below).

Inside loops:

$libinclude gnuplotxyz <parameter name> <xaxis element> <yaxis element>

After loop:

[$setglobal gp_loop1 no]

[$setglobal gp_loop2 no]

[$setglobal gp_loop3 no]

[$setglobal gp_loop4 no]

(Home 2D Plots 3D Plots Multi-Plots Spiderplots Examples Options)

3D Plots

3D - No loop

The data to be graphed as 3D-plot must be contained in a four-dimensional parameter, i.e. a parameter with four indexes. The elements in the first argument determine the different planes in a plot. The elements in the second argument determine the number of x-axis values. The number of elements in the third argument determines the number of y-axis values. The order of the elements in the second and third index determines how the different data points pertaining to one plane are connected. The remaining argument (fourth index) must contain at least three set elements of which one represents the x-axis, another one the y-axis coordinate, and a third one the z-axis coordinate.

$libinclude gnuplotxyz <parameter name> <xaxis element> <yaxis element> <zaxis element>

3D - Loop

Outside (above) loops: $libinclude gnuplotxyz

[$setglobal gp_loop1 <setname1>]

[$setglobal gp_loop2 <setname2>]

[$setglobal gp_loop3 <setname3>]

[$setglobal gp_loop4 <setname4>]

The statements in square brackets above are optional. If used, the title of the graph will show the current element of the loop. You can "unset" the values of these variables by assigning "no" or "0" (see below).

Inside loops:

$libinclude gnuplotxyz <parameter name> <xaxis element> <yaxis element> <zaxis element>

After loop: [$setglobal gp_loop1 no]

[$setglobal gp_loop2 no]

[$setglobal gp_loop3 no]

[$setglobal gp_loop4 no]

(Home 2D Plots 3D Plots Multi-Plots Spiderplots Examples Options)

Multiplots

The basic syntax is

$setglobal gp_multiplot yes

$setglobal gp_multiplotlayout <number of rows>,<number of columns>

$libinclude gnuplotyxyz <parameter name>

more <$libinclude gnuplotyxyz <parameter name>> statements

$libinclude gnuplotyxyz multiplot

This sequence of commands will plot all parameters between the $setglobal gp_multiplot yes and $libinclude gnuplotyxyz multiplot into a single multiplot. I have not tested how many plots gnuplot allows to combine. The statement $libinclude gnuplotyxyz multiplot executes the multiplot and also resets gp_multiplot to no.

Optional multiplot formatting

[$setglobal gp_multiplottitle <my multiplot title>]

[$setglobal gp_multiplottitlefont <font name, font size>]

In addition, before every individual plot statement, one can use all other options. For example, one can show the legend for a particular plot but deactivate it for others ($setglobal gp_key no). To set up multiplots nicely, you have to experiment a bit with options. Particularly, try different values for gp_bmargin, gp_tmargin, gp_lmargin, gp_rmargin. In the title, you can add \n. This causes a new line and will shift the position of the title. The same goes for axis titles (gp_xlabel, gp_ylabel).

Spiderplots

Important: Spider plots require gnuplot version 5.4.
The basic syntax is

$setglobal gp_style spiderplot

$libinclude gnuplotxyz <2-dimensional parameter>

(Home 2D Plots 3D Plots Multi-Plots Spiderplots Examples Options)

Examples

2D plots Download example_2Dplots.gms

2 dimensional Histograms Download example_histograms.gms

New Histogram Plots Download example_newhistograms.gms

2D Mixed Styles Download example_mixedstyles.gms

Fix Colors Download example_fixedcolors.gms

2D Fill Space between lines Download example_filledlines.gms

2D Loop (may not be suitable for all ages ;)

3D Plots Download example_3Dplots.gms

Text Labels Download example_textlabels.gms

Function plots Download example_functionplots.gms

Multi plots Download example_multiplots.gms

Multi plots 2 Download example_multiplots2.gms

Spiderplots Download example_spiderplots.gms

(Home 2D Plots 3D Plots Multi-Plots Spiderplots Examples Options)

Options

Through use of global variables, the format of the plot can be changed. If it doesn't work at all or not as you intended, you can examine gnuplotxyz.gms to find out how it is used and to fix the problem.

Syntax for options

$setglobal <option> <value>

terminal types

$setglobal gp_term wxt

other terminal values for gp_term include emf, gif, svg, ... some options may not work properly with non-windows terminals

Key options

gp_key, gp_keytitle, gp_keybox, gp_keyopt

Style options

gp_color, gp_title, gp_size

gp_style, gp_fill, gp_rectangle, gp_hist

gp_linewidth, gp_pointsize`

gp_grid, gp_xgrid, gp_ygrid

gp_zeroax, gp_xzeroax, gp_yzeroax

gp_border, gp_borddim

gp_bmargin, gp_tmargin, gp_rmargin, gp_lmargin (for manually specifying margins)

gp_l1style ... gp_l16style

gp_l1axes ... gp_l16axes

gp_lw_1, ... gp_lw_16 (for specifying the width of individual lines)

gp_lc_1 ... gp_lc_16 (right-click use link in new tab for: see available color names)

gp_fixcolor_set (for keeping the same color over a set)

Colors

There are several options to change colors

  • change the color palette via gp_palette. There are several ways to define palettes as explained in the gnuplot documentation set palette
  • change the color box via gp_colorbox See gnuplot documentation set colorbox
  • change individual colors (line 1 to line 20) using preprogrammed colors
  • automatically assign colors from a loaded palette to lines or bars using $setglobal gp_loadpalette with Palettes defined by Hagen Wierstorf and $setglobal gp_palette_fractions <number> to specify the number of lines/bars, $setglobal gp_palette_min and/or $setglobal gp_palette_max to define which range of the palette to use. If the palette colors should come in reverse order, then use $setglobal gp_palette negative
  • You can also create your own color spectrum using tools from the internet such as the colorbrewer or Leonardo Colors

Axis

gp_x2axis, gp_y2axis

gp_label, gp_xlabel, gp_ylabel, gp_zlabel, gp_x2label, gp_y2label

gp_ymin (useful when using a 2nd y-axis through y2scale)

gp_y2scale

gp_xrange, gp_yrange, gp_x2range, gp_y2range,

gp_tics, gp_xtics, gp_ytics, gp_xinc, gp_yinc

gp_logscale

Data

gp_supzero

gp_zeroend

Text Labels

gp_label_1 ... gp_label_9

Resetting

gp_resetstyle

gp_resetaxis

User Supplied Options

(these form entire lines before the plot statement in the gnuplot.inp file)

$setglobal gp_option_1 <value>

...

$setglobal gp_option_4 <value>

(Home 2D Plots 3D Plots Multi-Plots Spiderplots Examples Options)

Modification

Modifications of gnuplotxyz.gms may be necessary a) to implement additional plotting features and b) to fix bugs. The best way to fix a problem is to work backwards.

Step1: Open and examine the files "gnuplot.inp" and "gnuplot.dat" and determine a) wanted or b) misspecified commands/data (use gnuplot documentation if necessary)

Step2: Create a new file, i.e. "test.gms", in the same directory where "gnuplot.inp" and "gnuplot.dat" are put. The file should have the following content:

execute 'if exist "%SysEnv.APPDATA%\wgnuplot.ini" del "%SysEnv.APPDATA%\wgnuplot.ini" >nul';

execute 'copy gnuplot.inp gnuplot.ini >nul';

execute 'shellexecute wgnuplot.exe -persist gnuplot.inp';

Step3: Modify "gnuplot.inp" and/or "gnuplot.dat" and test by running "test.gms"

Step4: If you found out how "gnuplot.inp" and/or "gnuplot.dat" should be changed, modify statements in "gnuplotxyz.gms" to produce the desired content in "gnuplot.inp" and/or "gnuplot.dat"

(Home 2D Plots 3D Plots Multi-Plots Spiderplots Examples Options)