Addons/graphics/gnuplot

From J Wiki
Jump to: navigation, search
User Guide | Installation | Development | Categories | Git | Build Log

graphics/gnuplot - create gnuplot graphics

Creates gnuplot graphics from J data. Tested with gnuplot V4.


Installation

Use JAL/Package Manager or download the gnuplot archive from JAL:j601/addons and extract it into the ~addons/graphics/gnuplot folder.

Usage

Load with:

load 'graphics/gnuplot'

This populates locale pgnuplot.

Main Verbs

There are 3 main verbs: gplot, gsplot, gset.

gplot

Plots 2D graphics:

[cmd] gplot data

data is either an open array for a single plot, or a boxed list for multiple plots. This has the same format as for Plot.

cmd is options in a list delimited by , in gnuplot format, except that keywords should be spelled in full, e.g. use title not t.

There may be one option list per plot.

The first option list may start with a range indication. The last option list applies thereafter

gsplot

Plots surface graphics. The arguments are as for gplot.

[cmd] gsplot data

gset

Set one or more gnuplot options, in gnuplot format. You can set more than one option at a time, by delimiting each option with ; .

gset optionlist

Output

When gnuplot is run it creates two files in the ~temp directory:

gnu.plt      - plot commands
gnu.dat      - data

To display the plot, load gnuplot, then enter at the command prompt, using the correct path name:

load "gnu.plt"

In Windows, you can configure gnuplot to do this automatically.

Usage in Windows

In Windows, define GNUPLOTBIN_pgnuplot_ as the name of the gnuplot bin directory. A good place to define this is your startup script.

If defined, then:

  • the contents of gnuplot.ini are prefixed to the output file. This ensures the default values are read on start up.
  • wgnuplot.exe is called after generating the plot files.

In particular, the default style for data in gnuplot is points. To change this to lines, add the following to gnuplot.ini:

set style data lines

Notes

Titles default to empty

You can use the double quote character to delimit strings, e.g.

gset 'title "mydata"'

instead of:

gset 'title ''mydata'''

Strings must be delimited, i.e. not:

gset 'title mydata'

You can define GNUPLOTOUT_jgnuplot_ as the output directory for files written by J. By default this is ~temp.

Demos

load 'graphics/gnuplot/gpdemo'  NB. defines gp1, gp2, gp3, gp4


gp1=: 3 : 0
SC=: (;sin@^,:cos@^) steps _1 2 100
gset 'grid'
gset 'title "sin(exp) vs cos(exp)"'
gset 'xlabel "x-axis"'
gset 'ylabel "y-axis"'
'with lines title "sin(exp)", with lines title "cos(exp)"' gplot SC
)

Gp1.png

Author

The original script was contributed by L. Fraser Jackson.