diff --git a/dev/advanced/index.html b/dev/advanced/index.html index 258e0ab..aa51377 100644 --- a/dev/advanced/index.html +++ b/dev/advanced/index.html @@ -1,8 +1,8 @@ -Advanced techniques · Gnuplot.jl

Advanced techniques

Here we will show a few advanced techniques for data visualization using Gnuplot.jl.

Named datasets

A dataset may have an associated name whose purpose is to use it multiple times for plotting, while sending it only once to gnuplot. A dataset name must begin with a $.

A named dataset is defined as a Pair{String, Tuple}, e.g.:

"\$name" => (1:10,)

and can be used as an argument to both @gp and gsp, e.g.:

x = range(-2pi, stop=2pi, length=100);
+Advanced usage · Gnuplot.jl

Advanced usage

Here we will show a few advanced techniques for data visualization using Gnuplot.jl.

Named datasets

A dataset may have an associated name whose purpose is to use it multiple times for plotting, while sending it only once to gnuplot. A dataset name must begin with a $.

A named dataset is defined as a Pair{String, Tuple}, e.g.:

"\$name" => (1:10,)

and can be used as an argument to both @gp and gsp, e.g.:

x = range(-2pi, stop=2pi, length=100);
 y = sin.(x)
 name = "\$MyDataSet1"
-@gp name=>(x, y) "plot $name w l lc rgb 'black'" "pl $name u 1:(-1.5*\$2) w l lc rgb 'red'"

Both curves use the same input data, but the red curve has the second column (\$2, corresponding to the y value) is multiplied by a factor -1.5.

A named dataset comes in hand also when using gnuplot to fit experimental data to a model, e.g.:

# Generate data and some noise to simulate measurements
+@gp name=>(x, y) "plot $name w l lc rgb 'black'" "pl $name u 1:(1.5*\$2) w l lc rgb 'red'"

Both curves use the same input data, but the red curve has the second column (\$2, corresponding to the y value) multiplied by a factor 1.5.

A named dataset comes in hand also when using gnuplot to fit experimental data to a model, e.g.:

# Generate data and some noise to simulate measurements
 x = range(-2pi, stop=2pi, length=20);
 y = 1.5 * sin.(0.3 .+ 0.7x);
 err = 0.1 * maximum(abs.(y)) .* fill(1, size(x));
@@ -13,12 +13,12 @@ name = "\$MyDataSet1"
 @gp :- "a=1" "b=1" "c=1"             :- # set parameter initial values
 @gp :- name=>(x, y, err)             :- # define a named dataset
 @gp :- "fit f(x) $name via a, b, c;"    # fit the data

The parameter best fit values can be retrieved as follows:

@info("Best fit values:",
-a=Gnuplot.exec("print a"),
-b=Gnuplot.exec("print b"),
-c=Gnuplot.exec("print c"))
┌ Info: Best fit values:
-│   a = "1.53999342784748"
-│   b = "0.312000243313806"
-└   c = "0.71603533340826"

A named dataset is available until the session is reset, i.e. as long as :- is used as first argument to @gp.

Multiplot

Gnuplot.jl can draw multiple plots in the same figure by exploiting the multiplot command. Each plot is identified by a positive integer number, which can be used as argument to @gp to redirect commands to the appropriate plot.

Continuing previous example we can plot both data and best fit model (in plot 1) and residuals (in plot 2):

@gp :- "set multiplot layout 2,1"
+a = gpexec("print a"),
+b = gpexec("print b"),
+c = gpexec("print c"))
┌ Info: Best fit values:
+│   a = "1.51303854468398"
+│   b = "0.360996772821728"
+└   c = "0.700373449674559"

A named dataset is available until the session is reset, i.e. as long as :- is used as first argument to @gp.

Multiplot

Gnuplot.jl can draw multiple plots in the same figure by exploiting the multiplot command. Each plot is identified by a positive integer number, which can be used as argument to @gp to redirect commands to the appropriate plot.

Continuing previous example we can plot both data and best fit model (in plot 1) and residuals (in plot 2):

@gp :- "set multiplot layout 2,1"
 @gp :- 1 "p $name w errorbars t 'Data'"
 @gp :-   "p $name u 1:(f(\$1)) w l t 'Best fit model'"
 @gp :- 2 "p $name u 1:((f(\$1)-\$2) / \$3):(1) w errorbars t 'Resid. [{/Symbol s}]'"
@@ -35,8 +35,61 @@ c=Gnuplot.exec("print c"))

Multiple sessions

Gnuplot.jl can handle multiple sessions, i.e. multiple gnuplot processes running simultaneously. Each session is identified by a symbol.

In order to redirect commands to a specific session simply insert a symbol into your @gp or @gsp call, e.g.:

@gp :GP1 "plot sin(x)"    # opens first window
+@gsp :- 2 x y fxy "w pm3d notit"

Multiple sessions

Gnuplot.jl can handle multiple sessions, i.e. multiple gnuplot processes running simultaneously. Each session is identified by an ID (sid::Symbol, in the documentation).

In order to redirect commands to a specific session simply insert a symbol into your @gp or @gsp call, e.g.:

@gp :GP1 "plot sin(x)"    # opens first window
 @gp :GP2 "plot sin(x)"    # opens secondo window
-@gp :- :GP1 "plot cos(x)" # add a plot on first window

If the session ID is not specified the :default session is considered.

The names of all current sessions can be retrieved with session_names():

julia> println(session_names())
-Symbol[:GP1, :default, :GP2]

To quit a specific session use Gnuplot.quit():

julia> Gnuplot.quit(:GP1)
-0

The output value is the exit status of the underlying gnuplot process.

You may also quit all active sessions at once with Gnuplot.quitall():

julia> Gnuplot.quitall()

Histograms (1D)

Histograms (2D)

Contour lines

Animations

Dry sessions

Options

+@gp :- :GP1 "plot cos(x)" # add a plot on first window

The session ID can appear in every position in the argument list, but only one ID can be present in each call. If the session ID is not specified the :default session is considered.

The names of all current sessions can be retrieved with session_names():

julia> println(session_names())
+Symbol[:default, :GP1, :GP2]

To quit a specific session use Gnuplot.quit():

julia> Gnuplot.quit(:GP1)
+0

The output value is the exit status of the underlying gnuplot process.

You may also quit all active sessions at once with Gnuplot.quitall():

julia> Gnuplot.quitall()

Histograms

Gnuplot.jl provides facilities to compute and display histograms, through the hist() function. E.g., to quickly preview an histogram:

x = randn(1000);
+@gp hist(x)

A finer control on the output is achieved by setting the range to consider (range= keyword) and either the bin size (bs=) or the total number of bins (nbins=) in the histogram. See hist() documentation for further information.

Moreover, the hist() return a Gnuplot.Histogram1D structure, whose content can be exploited to customize histogram appearence, e.g.:

x = randn(1000);
+h = hist(x, range=3 .* [-1,1], bs=0.5)
+@gp h.bins h.counts "w histep t 'Data' lc rgb 'red'"

Gnuplot.jl also allows to compute 2D histograms by passing two vectors (with the same lengths) to hist(). A quick preview is simply obtained by:

x = randn(10_000)
+y = randn(10_000)
+@gp "set size ratio -1" hist(x, y)

Again, a finer control can be achieved by specifying ranges, bin size or number of bins (along both dimensions) and by explicitly using the content of the returned Gnuplot.Histogram2D structure:

h = hist(x, y, bs1=0.25, nbins2=20, range1=[-3,3], range2=[-3,3])
+@gp "set size ratio -1" h.bins1 h.bins2 h.counts "w image notit"

Alternatively, 2D histograms may be displayed using the boxxyerror plot style which allows more flexibility in, e.g., handling transparencies and drawing the histogram grid. In this case the data can be prepared using the boxxyerror() function, as follows:

box = boxxyerror(h.bins1, h.bins2, cartesian=true)
+@gp "set size ratio -1" "set style fill solid 0.5 border lc rgb 'gray'" :-
+@gp :- box... h.counts "w boxxyerror notit lc pal"

Contour lines

Although gnuplot already handles contours by itself (with the set contour command), Gnuplot.jl provides a way to calculate contour lines paths before displaying them, using the contourlines() function. We may use it for, e.g., plot contour lines with customized widths and palette, according to their z level. Continuing previous example:

clines = contourlines(h.bins1, h.bins2, h.counts, cntrparam="levels discrete 10, 30, 60, 90");
+for i in 1:length(clines)
+    @gp :- clines[i].data "w l t '$(clines[i].z)' lw $i lc pal" :-
+end
+@gp :- key="outside top center box horizontal"

Animations

The Multiplot capabilities can also be used to stack plots one above the other in order to create an animation, as in the following example:

x = y = -10:0.33:10
+fz(x,y) = sin.(sqrt.(x.^2 + y.^2))./sqrt.(x.^2+y.^2)
+fxy = [fz(x,y) for x in x, y in y]
+@gsp "set xyplane at 0" "unset colorbox" cb=[-1,1] zr=[-1,1]
+frame = 0
+for direction in [-1,1]
+    for factor in -1:0.1:1
+        global frame += 1
+        @gsp :- frame x y direction * factor .* fxy "w pm3d notit" :-
+    end
+end
+@gsp

Here the frame variable is used as multiplot index. The animation can be saved in a GIF file with:

save(term="gif animate size 480,360 delay 5", output="assets/animation.gif")

Direct command execution

When gnuplot commands are passed to @gp or @gsp they are stored in a session for future use, or to be saved in Gnuplot scripts. If you simply wish to execute a command, without storing it in the session, use gpexec. E.g. if you wish to temporarily change the current terminal:

julia> gpexec("set term wxt");

The gnuplot process replies are returned as a string, e.g.:

julia> gpexec("print GPVAL_TERM")
+"wxt"

You may also provide a session ID as first argument (see Multiple sessions, to redirect the command to a specific session.

Dry sessions

A "dry session" is a session with no underlying gnuplot process. To enable dry sessions type:

julia> Gnuplot.options.dry = true;

before starting a session (see also Options). Note that the dry option is a global one, i.e. it affects all sessions started after setting the option.

Clearly, no plot can be generated in dry sessions. Still, they are useful to run Gnuplot.jl code without raising errors (no attempt will be made to communicate with the underlying process). Moreover, Gnuplot scripts can also be generated in a dry session, without the additional overhead of sending data to the gnuplot process.

If a gnuplot process can not be started the package will print a warning, and automatically enable dry sessions.

Options

Thepackage options are stored in a global structure available in Julia as Gnuplot.option (the type of the structure is Gnuplot.Options). The most important settings are as follows:

  • dry::Bool: if true all new sessions will be started Dry sessions. Default is false, but if the package is not able to start a gnuplot it will automatically switch to false;

  • init::Vector{String}: This vector can be used to push! initialization commands to be executed when a new session is started. Default is an empty vector. It can be used to, e.g., set a custom terminal for all new sessions:

julia> push!(Gnuplot.options.init, "set term sixelgd");

Note that this is a global option, i.e. it will affect all new sessions. Also note that the commands in Gnuplot.options.init are not saved in Gnuplot scripts;

  • verbose::Bool: a flag to set verbosity of the package. In particular if it is true all communication with the underlying process will be printed on stdout. E.g.:

+julia> Gnuplot.options.verbose = true;
+
+julia> x = 1.:10;
+
+julia> @gp x x.^2 "w l t 'Parabola'"
+GNUPLOT (default) reset session
+GNUPLOT (default) $data1 << EOD
+GNUPLOT (default)  1.0 1.0
+GNUPLOT (default)  2.0 4.0
+GNUPLOT (default)  3.0 9.0
+GNUPLOT (default)  4.0 16.0
+GNUPLOT (default) ...
+GNUPLOT (default) EOD
+GNUPLOT (default) reset
+GNUPLOT (default) plot  \
+  $data1 w l t 'Parabola'
+
+julia> save(term="pngcairo size 480,360 fontscale 0.8", output="output.png")
+GNUPLOT (default) reset
+GNUPLOT (default) print GPVAL_TERM
+GNUPLOT (default) -> wxt
+GNUPLOT (default) print GPVAL_TERMOPTIONS
+GNUPLOT (default) -> 0 enhanced
+GNUPLOT (default) set term pngcairo size 480,360 fontscale 0.8
+GNUPLOT (default) set output 'output.png'
+GNUPLOT (default) plot  \
+  $data1 w l t 'Parabola'
+GNUPLOT (default) set output
+GNUPLOT (default) set term wxt 0 enhanced

Each line reports the package name (GNUPLOT), the session name (default), the command or string being sent to gnuplot process, and the returned response (line starting with ->). Default value is false;

  • cmd::String: command to start the gnuplot process, default value is "gnuplot". If you need to specify a custom path to the gnuplot executable you may change this value;

  • default::Symbol: default session name, i.e. the session that will be used when no session name is provided;

  • preferred_format::Symbol: preferred format to send data to gnuplot. Value must be one of:

    • bin: provides best performances for large datasets, but uses temporary files;
    • text: may be slow for large datasets, but no temporary file is involved;
    • auto (default) automatically choose the best strategy.
diff --git a/dev/api/index.html b/dev/api/index.html index b44ced5..7aa3427 100644 --- a/dev/api/index.html +++ b/dev/api/index.html @@ -1,29 +1,29 @@ -API · Gnuplot.jl

API

Index

Exported symbols

The list of Gnuplot.jl exported symbols is as follows:

Gnuplot.@gpMacro
@gp args...

The @gp macro, and its companion @gsp for 3D plots, allows to send data and commands to the gnuplot using an extremely concise syntax. The macros accepts any number of arguments, with the following meaning:

  • one, or a group of consecutive, array(s) build up a dataset. The different arrays are accessible as columns 1, 2, etc. from the gnuplot process. The number of required input arrays depends on the chosen plot style (see gnuplot documentation);

  • a string occurring before a dataset is interpreted as a gnuplot command (e.g. set grid);

  • a string occurring immediately after a dataset is interpreted as a plot element for the dataset, by which you can specify using clause, with clause, line styles, etc.. All keywords may be abbreviated following gnuplot conventions. Moreover, "plot" and "splot" can be abbreviated to "p" and "s" respectively;

  • the special symbol :-, whose meaning is to avoid starting a new plot (if given as first argument), or to avoid immediately running all commands to create the final plot (if given as last argument). Its purpose is to allow splitting one long statement into multiple (shorter) ones;

  • any other symbol is interpreted as a session ID;

  • an Int (>= 1) is interpreted as the plot destination in a multi-plot session (this specification applies to subsequent arguments, not previous ones);

  • an input in the form "\$name"=>(array1, array2, etc...) is interpreted as a named dataset. Note that the dataset name must always start with a "$";

  • an input in the form keyword=value is interpreted as a keyword/value pair. The accepted keywords and their corresponding gnuplot commands are as follows:

    • xrange=[low, high] => "set xrange [low:high];
    • yrange=[low, high] => "set yrange [low:high];
    • zrange=[low, high] => "set zrange [low:high];
    • cbrange=[low, high]=> "set cbrange[low:high];
    • key="..." => "set key ...";
    • title="..." => "set title "..."";
    • xlabel="..." => "set xlabel "..."";
    • ylabel="..." => "set ylabel "..."";
    • zlabel="..." => "set zlabel "..."";
    • xlog=true => set logscale x;
    • ylog=true => set logscale y;
    • zlog=true => set logscale z.

All Keyword names can be abbreviated as long as the resulting name is unambiguous. E.g. you can use xr=[1,10] in place of xrange=[1,10].

source
Gnuplot.@gspMacro
@gsp args...

This macro accepts the same syntax as @gp, but produces a 3D plot instead of a 2D one.

source
Gnuplot.contourlinesFunction
contourlines(x::Vector{Float64}, y::Vector{Float64}, h::Matrix{Float64}; cntrparam="level auto 10")

Compute paths of contour lines for 2D data, and return a vector of IsoContourLines object.

Arguments:

  • x, y: Coordinates;
  • h: the levels on which iso contour lines are to be calculated
  • cntrparam: settings to compute contour line paths (see gnuplot documentation for cntrparam).

Example

x = randn(5000);
+API · Gnuplot.jl

API

Index

Exported symbols

The list of Gnuplot.jl exported symbols is as follows:

Gnuplot.@gpMacro
@gp args...

The @gp macro, and its companion @gsp for 3D plots, allows to send data and commands to the gnuplot using an extremely concise syntax. The macros accepts any number of arguments, with the following meaning:

  • one, or a group of consecutive, array(s) build up a dataset. The different arrays are accessible as columns 1, 2, etc. from the gnuplot process. The number of required input arrays depends on the chosen plot style (see gnuplot documentation);

  • a string occurring before a dataset is interpreted as a gnuplot command (e.g. set grid);

  • a string occurring immediately after a dataset is interpreted as a plot element for the dataset, by which you can specify using clause, with clause, line styles, etc.. All keywords may be abbreviated following gnuplot conventions. Moreover, "plot" and "splot" can be abbreviated to "p" and "s" respectively;

  • the special symbol :-, whose meaning is to avoid starting a new plot (if given as first argument), or to avoid immediately running all commands to create the final plot (if given as last argument). Its purpose is to allow splitting one long statement into multiple (shorter) ones;

  • any other symbol is interpreted as a session ID;

  • an Int (>= 1) is interpreted as the plot destination in a multi-plot session (this specification applies to subsequent arguments, not previous ones);

  • an input in the form "\$name"=>(array1, array2, etc...) is interpreted as a named dataset. Note that the dataset name must always start with a "$";

  • an input in the form keyword=value is interpreted as a keyword/value pair. The accepted keywords and their corresponding gnuplot commands are as follows:

    • xrange=[low, high] => "set xrange [low:high];
    • yrange=[low, high] => "set yrange [low:high];
    • zrange=[low, high] => "set zrange [low:high];
    • cbrange=[low, high]=> "set cbrange[low:high];
    • key="..." => "set key ...";
    • title="..." => "set title "..."";
    • xlabel="..." => "set xlabel "..."";
    • ylabel="..." => "set ylabel "..."";
    • zlabel="..." => "set zlabel "..."";
    • xlog=true => set logscale x;
    • ylog=true => set logscale y;
    • zlog=true => set logscale z.

All Keyword names can be abbreviated as long as the resulting name is unambiguous. E.g. you can use xr=[1,10] in place of xrange=[1,10].

source
Gnuplot.@gspMacro
@gsp args...

This macro accepts the same syntax as @gp, but produces a 3D plot instead of a 2D one.

source
Gnuplot.contourlinesFunction
contourlines(x::Vector{Float64}, y::Vector{Float64}, h::Matrix{Float64}; cntrparam="level auto 10")

Compute paths of contour lines for 2D data, and return a vector of IsoContourLines object.

Arguments:

  • x, y: Coordinates;
  • h: the levels on which iso contour lines are to be calculated
  • cntrparam: settings to compute contour line paths (see gnuplot documentation for cntrparam).

Example

x = randn(5000);
 y = randn(5000);
 h = hist(x, y, nbins1=20, nbins2=20);
 clines = contourlines(h.bins1, h.bins2, h.counts, cntrparam="levels discrete 15, 30, 45");
 @gp "set size ratio -1"
 for i in 1:length(clines)
     @gp :- clines[i].data "w l t '$(clines[i].z)' dt $i"
-end
source
Gnuplot.dataset_namesFunction
dataset_names(sid::Symbol)
-dataset_names()

Return a vector with all dataset names for the sid session. If sid is not provided the default session is considered.

source
Gnuplot.histFunction
hist(v::Vector{T}; range=extrema(v), bs=NaN, nbins=0, pad=true) where T <: Number

Calculates the histogram of the values in v and returns a Histogram1D structure.

Arguments

  • v: a vector of values to compute the histogra;
  • range: values of the left edge of the first bin and of the right edge of the last bin;
  • bs: size of histogram bins;
  • nbins: number of bins in the histogram;
  • pad: if true add one dummy bins with zero counts before the first bin and after the last.

If bs is given nbins is ignored.

Example

v = randn(1000)
+end
source
Gnuplot.dataset_namesFunction
dataset_names(sid::Symbol)
+dataset_names()

Return a vector with all dataset names for the sid session. If sid is not provided the default session is considered.

source
Gnuplot.gpexecFunction
gpexec(sid::Symbol, command::String)
+gpexec(command::String)

Execute the gnuplot command command on the underlying gnuplot process of the sid session, and return the results as a Vector{String}. If a gnuplot error arises it is propagated as an ErrorException.

The the sid argument is not provided, the default session is considered.

Examples:

gpexec("print GPVAL_TERM")
+gpexec("plot sin(x)")
source
Gnuplot.histFunction
hist(v::Vector{T}; range=extrema(v), bs=NaN, nbins=0, pad=true) where T <: Number

Calculates the histogram of the values in v and returns a Histogram1D structure.

Arguments

  • v: a vector of values to compute the histogra;
  • range: values of the left edge of the first bin and of the right edge of the last bin;
  • bs: size of histogram bins;
  • nbins: number of bins in the histogram;
  • pad: if true add one dummy bins with zero counts before the first bin and after the last.

If bs is given nbins is ignored.

Example

v = randn(1000)
 h = hist(v, bs=0.5)
 @gp h  # preview
-@gp h.bins h.counts "w histep notit"
source
hist(v1::Vector{T1 <: Number}, v2::Vector{T2 <: Number}; range1=[NaN,NaN], bs1=NaN, nbins1=0, range2=[NaN,NaN], bs2=NaN, nbins2=0)

Calculates the 2D histogram of the values in v1 and v2 and returns a Histogram2D structure.

Arguments

  • v1: a vector of values along the first dimension;
  • v2: a vector of values along the second dimension;
  • range1: values of the left edge of the first bin and of the right edge of the last bin, along the first dimension;
  • range1: values of the left edge of the first bin and of the right edge of the last bin, along the second dimension;
  • bs1: size of histogram bins along the first dimension;
  • bs2: size of histogram bins along the second dimension;
  • nbins1: number of bins along the first dimension;
  • nbins2: number of bins along the second dimension;

If bs1 (bs2) is given nbins1 (nbins2) is ignored.

Example

v1 = randn(1000)
+@gp h.bins h.counts "w histep notit"
source
hist(v1::Vector{T1 <: Number}, v2::Vector{T2 <: Number}; range1=[NaN,NaN], bs1=NaN, nbins1=0, range2=[NaN,NaN], bs2=NaN, nbins2=0)

Calculates the 2D histogram of the values in v1 and v2 and returns a Histogram2D structure.

Arguments

  • v1: a vector of values along the first dimension;
  • v2: a vector of values along the second dimension;
  • range1: values of the left edge of the first bin and of the right edge of the last bin, along the first dimension;
  • range1: values of the left edge of the first bin and of the right edge of the last bin, along the second dimension;
  • bs1: size of histogram bins along the first dimension;
  • bs2: size of histogram bins along the second dimension;
  • nbins1: number of bins along the first dimension;
  • nbins2: number of bins along the second dimension;

If bs1 (bs2) is given nbins1 (nbins2) is ignored.

Example

v1 = randn(1000)
 v2 = randn(1000)
 h = hist(v1, v2, bs1=0.5, bs2=0.5)
 @gp h  # preview
-@gp "set size ratio -1" "set auto fix" h.bins1 h.bins2 h.counts "w image notit"
source
Gnuplot.linetypesFunction
linetypes(cmap::ColorScheme)
-linetypes(s::Symbol)

Convert a ColorScheme object into a string containing the gnuplot commands to set up linetype colors.

If the argument is a Symbol it is interpreted as the name of one of the predefined schemes in ColorSchemes.

source
Gnuplot.paletteFunction
palette(cmap::ColorScheme)
-palette(s::Symbol)

Convert a ColorScheme object into a string containing the gnuplot commands to set up the corresponding palette.

If the argument is a Symbol it is interpreted as the name of one of the predefined schemes in ColorSchemes.

source
Gnuplot.saveFunction
save(sid::Symbol; term="", output="")
+@gp "set size ratio -1" "set auto fix" h.bins1 h.bins2 h.counts "w image notit"
source
Gnuplot.linetypesFunction
linetypes(cmap::ColorScheme; rev=false)
+linetypes(s::Symbol; rev=false)

Convert a ColorScheme object into a string containing the gnuplot commands to set up linetype colors.

If the argument is a Symbol it is interpreted as the name of one of the predefined schemes in ColorSchemes. If rev=true the line colors are reversed.

source
Gnuplot.paletteFunction
palette(cmap::ColorScheme; rev=false)
+palette(s::Symbol; rev=false)

Convert a ColorScheme object into a string containing the gnuplot commands to set up the corresponding palette.

If the argument is a Symbol it is interpreted as the name of one of the predefined schemes in ColorSchemes. If rev=true the palette is reversed.

source
Gnuplot.saveFunction
save(sid::Symbol; term="", output="")
 save(sid::Symbol, script_filename::String, ;term="", output="")
 save(; term="", output="")
-save(script_filename::String ;term="", output="")

Export a (multi-)plot into the external file name provided in the output= keyword. The gnuplot terminal to use is provided through the term= keyword.

If the script_filename argument is provided a gnuplot script will be written in place of the output image. The latter can then be used in a pure gnuplot session (Julia is no longer needed) to generate exactly the same original plot.

If the sid argument is provided the operation applies to the corresponding session.

source
Gnuplot.statsFunction
stats(sid::Symbol,name::String)
+save(script_filename::String ;term="", output="")

Export a (multi-)plot into the external file name provided in the output= keyword. The gnuplot terminal to use is provided through the term= keyword.

If the script_filename argument is provided a gnuplot script will be written in place of the output image. The latter can then be used in a pure gnuplot session (Julia is no longer needed) to generate exactly the same original plot.

If the sid argument is provided the operation applies to the corresponding session.

source
Gnuplot.statsFunction
stats(sid::Symbol,name::String)
 stats(name::String)
 stats(sid::Symbol)
-stats()

Print a statistical summary for the name dataset, belonging to sid session. If name is not provdied a summary is printed for each dataset in the session. If sid is not provided the default session is considered.

This function is actually a wrapper for the gnuplot command stats.

source
Gnuplot.terminalsFunction
terminals()

Return a Vector{String} with the names of all the available gnuplot terminals.

source
Gnuplot.terminalFunction
terminal(sid::Symbol)
-terminal()

Return a String with the current gnuplot terminal (and its options) of the process associated to session sid, or to the default session (if sid is not provided).

source
Gnuplot.test_terminalFunction
test_terminal(term=nothing; linetypes=nothing, palette=nothing)

Run the test and test palette commands on a gnuplot terminal.

If no term is given it will use the default terminal. If linetypes and palette are given they are used as input to the linetypes and palette function repsetcively to load the associated color scheme.

Examples

test_terminal()
-test_terminal("wxt", linetypes=:rust, palette=:viridis)
source

Non-exported symbols

The following functions are not exported by the Gnuplot.jl package since they are typically not used in every day work, or aimed to debugging purposes. Still, they can be useful in some case, hence they are documented here.

In order to call these functions you should add the Gnuplot. prefix to the function name.

Gnuplot.Histogram1DType
Histogram1D

A 1D histogram data.

Fields

  • bins::Vector{Float64}: middle points of the bins;
  • counts::Vector{Float64}: couts in the bins;
  • binsize::Float64: size of each bin;
source
Gnuplot.Histogram2DType
Histogram2D

A 2D histogram data.

Fields

  • bins1::Vector{Float64}: middle points of the bins along first dimension;
  • bins2::Vector{Float64}: middle points of the bins along second dimension;
  • counts::Vector{Float64}: couts in the bins;
  • binsize1::Float64: size of each bin along first dimension;
  • binsize2::Float64: size of each bin along second dimension;
source
Gnuplot.IsoContourLinesType
IsoContourLines

Coordinates of all contour lines of a given level.

Fields

  • paths::Vector{Path2d}: vector of Path2d objects, one for each continuous path;
  • data::Vector{String}: vector with string representation of all paths (ready to be sent to gnuplot);
  • z::Float64: level of the contour lines.
source
Gnuplot.OptionsType
Options

Structure containing the package global options, accessible through Gnuplot.options.

Fields

  • dry::Bool: whether to use dry sessions, i.e. without an underlying Gnuplot process (default: false)
  • cmd::String: command to start the Gnuplot process (default: "gnuplot")
  • default::Symbol: default session name (default: :default)
  • init::Vector{String}: commands to initialize the gnuplot session (e.g., to set default terminal)
  • verbose::Bool: verbosity flag (default: false)
  • preferred_format::Symbol: preferred format to send data to gnuplot. Value must be one of:
    • bin: fastest solution for large datasets, but uses temporary files;
    • text: may be slow for large datasets, but no temporary file is involved;
    • auto (default) automatically choose the best strategy.
source
Gnuplot.execFunction
Gnuplot.exec(sid::Symbol, command::String)
-Gnuplot.exec(command::String)

Execute the gnuplot command command on the underlying gnuplot process of the sid session, and return the results as a Vector{String}. If a gnuplot error arises it is propagated as an ErrorException.

The the sid argument is not provided, the default session is considered.

Examples:

Gnuplot.exec("print GPVAL_TERM")
-Gnuplot.exec("plot sin(x)")
source
Gnuplot.gpversionFunction
Gnuplot.gpversion()

Return the gnuplot application version.

Raise an error if version is < 5.0 (required to use data blocks).

source
Gnuplot.quitFunction
Gnuplot.quit(sid::Symbol)

Quit the session identified by sid and the associated gnuplot process (if any).

source
Gnuplot.quitallFunction
Gnuplot.quitall()

Quit all the sessions and the associated gnuplot processes.

source
+stats()

Print a statistical summary for the name dataset, belonging to sid session. If name is not provdied a summary is printed for each dataset in the session. If sid is not provided the default session is considered.

This function is actually a wrapper for the gnuplot command stats.

source
Gnuplot.terminalsFunction
terminals()

Return a Vector{String} with the names of all the available gnuplot terminals.

source
Gnuplot.terminalFunction
terminal(sid::Symbol)
+terminal()

Return a String with the current gnuplot terminal (and its options) of the process associated to session sid, or to the default session (if sid is not provided).

source
Gnuplot.test_terminalFunction
test_terminal(term=nothing; linetypes=nothing, palette=nothing)

Run the test and test palette commands on a gnuplot terminal.

If no term is given it will use the default terminal. If lt and pal are given they are used as input to the linetypes and palette function repsetcively to load the associated color scheme.

Examples

test_terminal()
+test_terminal("wxt", lt=:rust, pal=:viridis)
source

Non-exported symbols

The following functions are not exported by the Gnuplot.jl package since they are typically not used in every day work, or aimed to debugging purposes. Still, they can be useful in some case, hence they are documented here.

In order to call these functions you should add the Gnuplot. prefix to the function name.

Gnuplot.Histogram1DType
Histogram1D

A 1D histogram data.

Fields

  • bins::Vector{Float64}: bin center values;
  • counts::Vector{Float64}: counts in the bins;
  • binsize::Float64: size of each bin;
source
Gnuplot.Histogram2DType
Histogram2D

A 2D histogram data.

Fields

  • bins1::Vector{Float64}: bin center values along first dimension;
  • bins2::Vector{Float64}: bin center values along second dimension;
  • counts::Vector{Float64}: counts in the bins;
  • binsize1::Float64: size of each bin along first dimension;
  • binsize2::Float64: size of each bin along second dimension;
source
Gnuplot.IsoContourLinesType
IsoContourLines

Coordinates of all contour lines of a given level.

Fields

  • paths::Vector{Path2d}: vector of Path2d objects, one for each continuous path;
  • data::Vector{String}: vector with string representation of all paths (ready to be sent to gnuplot);
  • z::Float64: level of the contour lines.
source
Gnuplot.OptionsType
Options

Structure containing the package global options, accessible through Gnuplot.options.

Fields

  • dry::Bool: whether to use dry sessions, i.e. without an underlying Gnuplot process (default: false)
  • cmd::String: command to start the Gnuplot process (default: "gnuplot")
  • default::Symbol: default session name (default: :default)
  • init::Vector{String}: commands to initialize the gnuplot session (e.g., to set default terminal)
  • verbose::Bool: verbosity flag (default: false)
  • preferred_format::Symbol: preferred format to send data to gnuplot. Value must be one of:
    • bin: fastest solution for large datasets, but uses temporary files;
    • text: may be slow for large datasets, but no temporary file is involved;
    • auto (default) automatically choose the best strategy.
source
Gnuplot.gpversionFunction
Gnuplot.gpversion()

Return the gnuplot application version.

Raise an error if version is < 5.0 (required to use data blocks).

source
Gnuplot.quitFunction
Gnuplot.quit(sid::Symbol)

Quit the session identified by sid and the associated gnuplot process (if any).

source
Gnuplot.quitallFunction
Gnuplot.quitall()

Quit all the sessions and the associated gnuplot processes.

source
diff --git a/dev/assets/animation.gif b/dev/assets/animation.gif new file mode 100644 index 0000000..d2e47ad Binary files /dev/null and b/dev/assets/animation.gif differ diff --git a/dev/assets/cairolatex.png b/dev/assets/cairolatex.png new file mode 100644 index 0000000..cd4713b Binary files /dev/null and b/dev/assets/cairolatex.png differ diff --git a/dev/assets/ex001.png b/dev/assets/ex001.png index c7d4831..8ac0b40 100644 Binary files a/dev/assets/ex001.png and b/dev/assets/ex001.png differ diff --git a/dev/assets/ex002.png b/dev/assets/ex002.png index 00168c1..1f729d2 100644 Binary files a/dev/assets/ex002.png and b/dev/assets/ex002.png differ diff --git a/dev/assets/ex003.png b/dev/assets/ex003.png index b0a1792..ee31b1d 100644 Binary files a/dev/assets/ex003.png and b/dev/assets/ex003.png differ diff --git a/dev/assets/ex004.png b/dev/assets/ex004.png index 31de506..669a3d0 100644 Binary files a/dev/assets/ex004.png and b/dev/assets/ex004.png differ diff --git a/dev/assets/ex005.png b/dev/assets/ex005.png index fffb23d..74219a6 100644 Binary files a/dev/assets/ex005.png and b/dev/assets/ex005.png differ diff --git a/dev/assets/ex006.png b/dev/assets/ex006.png index 3638b69..af3a638 100644 Binary files a/dev/assets/ex006.png and b/dev/assets/ex006.png differ diff --git a/dev/assets/ex007a.png b/dev/assets/ex007a.png index adde206..0ab3442 100644 Binary files a/dev/assets/ex007a.png and b/dev/assets/ex007a.png differ diff --git a/dev/assets/ex007b.png b/dev/assets/ex007b.png index b91fa0c..b900a1e 100644 Binary files a/dev/assets/ex007b.png and b/dev/assets/ex007b.png differ diff --git a/dev/assets/ex007c.png b/dev/assets/ex007c.png index fb3caba..9e35488 100644 Binary files a/dev/assets/ex007c.png and b/dev/assets/ex007c.png differ diff --git a/dev/assets/ex008.png b/dev/assets/ex008.png index 3978fe6..f944a84 100644 Binary files a/dev/assets/ex008.png and b/dev/assets/ex008.png differ diff --git a/dev/assets/ex008a.png b/dev/assets/ex008a.png index 4d7bc56..58551a7 100644 Binary files a/dev/assets/ex008a.png and b/dev/assets/ex008a.png differ diff --git a/dev/assets/ex009.png b/dev/assets/ex009.png index 9943bc2..81a3f73 100644 Binary files a/dev/assets/ex009.png and b/dev/assets/ex009.png differ diff --git a/dev/assets/ex010.png b/dev/assets/ex010.png index c452d49..553c3fe 100644 Binary files a/dev/assets/ex010.png and b/dev/assets/ex010.png differ diff --git a/dev/assets/ex011.png b/dev/assets/ex011.png index badae7e..33cb578 100644 Binary files a/dev/assets/ex011.png and b/dev/assets/ex011.png differ diff --git a/dev/assets/ex012.png b/dev/assets/ex012.png index 0981bec..a5d1718 100644 Binary files a/dev/assets/ex012.png and b/dev/assets/ex012.png differ diff --git a/dev/assets/ex013a.png b/dev/assets/ex013a.png new file mode 100644 index 0000000..a5bd5e9 Binary files /dev/null and b/dev/assets/ex013a.png differ diff --git a/dev/assets/ex013b.png b/dev/assets/ex013b.png new file mode 100644 index 0000000..379a784 Binary files /dev/null and b/dev/assets/ex013b.png differ diff --git a/dev/assets/ex014a.png b/dev/assets/ex014a.png new file mode 100644 index 0000000..e6ac284 Binary files /dev/null and b/dev/assets/ex014a.png differ diff --git a/dev/assets/ex014b.png b/dev/assets/ex014b.png new file mode 100644 index 0000000..bddb2f9 Binary files /dev/null and b/dev/assets/ex014b.png differ diff --git a/dev/assets/ex014c.png b/dev/assets/ex014c.png new file mode 100644 index 0000000..9589e48 Binary files /dev/null and b/dev/assets/ex014c.png differ diff --git a/dev/assets/ex014d.png b/dev/assets/ex014d.png new file mode 100644 index 0000000..1f8a782 Binary files /dev/null and b/dev/assets/ex014d.png differ diff --git a/dev/assets/sixelgd.png b/dev/assets/sixelgd.png new file mode 100644 index 0000000..92c1bc4 Binary files /dev/null and b/dev/assets/sixelgd.png differ diff --git a/dev/basic/index.html b/dev/basic/index.html index 0e95f78..6d3cf44 100644 --- a/dev/basic/index.html +++ b/dev/basic/index.html @@ -1,5 +1,5 @@ -Basic usage · Gnuplot.jl

Basic usage

The main purpose of the Gnuplot.jl package is to send data and commands to the underlying gnuplot process, in order to generate plots. Unlike other packages, however, the actual commands to plot, or the plot attributes, are not specified through function calls. This is what makes Gnuplot.jl easy to learn and use: there are no functions or keywords names to memorize[1].

The most important symbols exported by the package are the @gp (for 2D plots) and @gsp (for 3D plots) macros, both accepting any number of arguments, and whose meaning is interpreted as follows:

  • one, or a group of consecutive, array(s) build up a dataset. The different arrays are accessible as columns 1, 2, etc. from the gnuplot process. The number of required input arrays depends on the chosen plot style (see gnuplot documentation);

  • a string occurring before a dataset is interpreted as a gnuplot command (e.g. set grid);

  • a string occurring immediately after a dataset is interpreted as a plot element for the dataset, by which you can specify using clause, with clause, line styles, etc.;

  • the special symbol :-, whose meaning is to avoid starting a new plot (if given as first argument), or to avoid immediately running all commands to create the final plot (if given as last argument). Its purpose is to allow splitting one long statement into multiple (shorter) ones.

The above list shows all the fundamental concepts to follow the examples presented below. The @gp and @gsp macros also accepts further arguments, but their use will be discussed in Advanced techniques.

2D plots

Here we will show a few examples to generate 2D plots. The examples are intentionally very simple to highlight the behavior of Gnuplot.jl. See Examples for more complex ones.

Remember to run:

using Gnuplot

before running the examples.

Simple examples involving just gnuplot commands:


Plot a sinusoid:

@gp "plot sin(x)"


Plot two curves:

@gp "set key left" "plot sin(x)" "pl cos(x)"

Note

Note that all gnuplot commands can be abbreviated as long as the resulting string is not ambiguous. In the example above we used pl in place of plot.


Split a @gp call in three statements:

@gp    "set grid"  :-
+Basic usage · Gnuplot.jl

Basic usage

The main purpose of the Gnuplot.jl package is to send data and commands to the underlying gnuplot process, in order to generate plots. Unlike other packages, however, the actual commands to plot, or the plot attributes, are not specified through function calls. This is what makes Gnuplot.jl easy to learn and use: there are no functions or keywords names to memorize[1].

The most important symbols exported by the package are the @gp (for 2D plots) and @gsp (for 3D plots) macros, both accepting any number of arguments, and whose meaning is interpreted as follows:

  • one, or a group of consecutive, array(s) build up a dataset. The different arrays are accessible as columns 1, 2, etc. from the gnuplot process. The number of required input arrays depends on the chosen plot style (see gnuplot documentation);

  • a string occurring before a dataset is interpreted as a gnuplot command (e.g. set grid);

  • a string occurring immediately after a dataset is interpreted as a plot element for the dataset, by which you can specify using clause, with clause, line styles, etc.;

  • the special symbol :-, whose meaning is to avoid starting a new plot (if given as first argument), or to avoid immediately running all commands to create the final plot (if given as last argument). Its purpose is to allow splitting one long statement into multiple (shorter) ones.

The above list shows all the fundamental concepts to follow the examples presented below. The @gp and @gsp macros also accepts further arguments, but their use will be discussed in Advanced usage.

2D plots

Here we will show a few examples to generate 2D plots. The examples are intentionally very simple to highlight the behavior of Gnuplot.jl. See Examples for more complex ones.

Remember to run:

using Gnuplot

before running the examples.

Simple examples involving just gnuplot commands:


Plot a sinusoid:

@gp "plot sin(x)"


Plot two curves:

@gp "set key left" "plot sin(x)" "pl cos(x)"

Note

Note that all gnuplot commands can be abbreviated as long as the resulting string is not ambiguous. In the example above we used pl in place of plot.


Split a @gp call in three statements:

@gp    "set grid"  :-
 @gp :- "p sin(x)"  :-
 @gp :- "plo cos(x)"

Send data from Julia to gnuplot:

Plot a parabola

@gp (1:20).^2


Plot a parabola with scaled x axis, lines and legend

x = 1:20
 @gp "set key left"   x ./ 20   x.^2   "with lines tit 'Parabola'"


Multiple datasets, logarithmic axis, labels and colors, etc.

x = 1:0.1:10
@@ -42,4 +42,49 @@ end

The list of all av :flag :valentine :Oranges_4 - :avocado

Exporting plots to files

The save() function allows to export all plots (as well as multiplots, see Multiplot) to a file using one of the many available gnuplot terminals. To check which terminals are available in your platform type set term in your gnuplot terminal.

All plots in this page have been saved with:

save(term="pngcairo size 480,360", output="assets/output.png")

except the Lena image, saved with the jpeg terminal:

save(term="jpeg size 480,360", output="assets/output.png")

Gnuplot scripts

Besides exporting plots in a file Gnuplot.jl can also save a script, i.e. a file containing the minimum set of data and commands required to generate a plot within gnuplot.

To generate a script for one of the example above use:

save("script.gp")

after the plot has been displayed. The script can then be used within a gnuplot session as follows:

gunplot> load 'script.gp'

to generate a plot identical to the original one, without using the Julia language.

The purpose of gnuplot scripts is to allow sharing all data, alongside a plot, in order to foster collaboration among scientists and replicability of results. Moreover, a script can be used at any time to change the details of a plot, without the need to re-run the Julia code used to generate it the first time.

Finally, the scripts are the only possible output when Dry sessions are used (i.e. when gnuplot is not available in the user platform.

  • 1a previous knowledge of gnuplot usage is, nevertheless, required.
+ :avocado

Exporting plots to files

Gnuplot.jl to export all plots (as well as multiplots, see Multiplot) to an external file using one of the many available gnuplot terminals. To check which terminals are available in your platform type:

julia> terminals()
+59-element Array{String,1}:
+ "cairolatex"
+ "canvas"
+ "cgm"
+ "context"
+ "domterm"
+ "dpu414"
+ "dumb"
+ "dxf"
+ "eepic"
+ "emf"
+ ⋮
+ "tikz"
+ "tkcanvas"
+ "tpic"
+ "unknown"
+ "vttek"
+ "wxt"
+ "x11"
+ "xlib"
+ "xterm"

(see also terminal() to check your current terminal).

Once you choose the proper terminal (i.e. format of the exported file), use the save() function to export. As an example, all the plots in this page have been saved with:

save(term="pngcairo size 480,360 fontscale 0.8", output="assets/output.png")

Note that you can pass both the terminal name and its options via the term= keyword. See Gnuplot terminals for further info on the terminals.

Gnuplot scripts

Besides exporting plots in a file Gnuplot.jl can also save a script, i.e. a file containing the minimum set of data and commands required to re-create a figure using just gnuplot.

To generate a script for one of the example above use:

save("script.gp")

after the plot has been displayed. Note that when images or large datasets are involved, save() may store the data in binary files under a directory named <script name>_data. In order to work properly both the script and the associated directory must be available in the same directory.

E.g., the following code:

x = 1:10
+@gp x x.^2 "w l"
+save("script1.gp")

will produce the following file, named script1.gp:

reset session
+$data1 << EOD
+ 1 1
+ 2 4
+ 3 9
+ 4 16
+ 5 25
+ 6 36
+ 7 49
+ 8 64
+ 9 81
+ 10 100
+EOD
+plot  \
+  $data1 w l
+set output

While the following:

img = testimage("lighthouse");
+@gp "set size square" "set autoscale fix" img "rotate=-90deg with rgbimage notit"
+save("script2.gp")

will produce:

reset session
+set size square
+set autoscale fix
+plot  \
+   './script2_data/jl_vH8X4k' binary array=(512, 768) rotate=-90deg with rgbimage notit
+set output

The above scripts can be loaded into a pure gnuplot session (Julia is no longer needed) as follows:

gunplot> load 'script1.gp'

to generate a plot identical to the original one.

The purpose of gnuplot scripts is to allow sharing all data, alongside a plot, in order to foster collaboration among scientists and replicability of results. Moreover, a script can be used at any time to change the details of a plot, without the need to re-run the Julia code used to generate it the first time.

Finally, the scripts are the only possible output when Dry sessions are used (i.e. when gnuplot is not available in the user platform.

diff --git a/dev/examples/index.html b/dev/examples/index.html index cc05936..aea901d 100644 --- a/dev/examples/index.html +++ b/dev/examples/index.html @@ -1,2 +1,2 @@ -Examples · Gnuplot.jl
+Examples · Gnuplot.jl

Examples

The official gallery of high quality examples is maintained in a separate repository:

https://lazarusa.github.io/gnuplot-examples/

The examples in this documentation are intentionally very simple, in order to focus on the package functionalities. The only relatively complex, publication-quality plot, is discussed in The cairolatex terminal section.

Keep in mind that Gnuplot.jl is just an interface to gnuplot, so everything you can do with the latter is achievable from Julia. Further gnuplot examples can be found here:

diff --git a/dev/index.html b/dev/index.html index 78d4364..870e35f 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,2 +1,2 @@ -Home · Gnuplot.jl

Gnuplot.jl

A Julia interface to gnuplot.

The Gnuplot.jl package allows easy and fast use of gnuplot as a data visualization tool in Julia. Have a look at Basic usage and Examples for a quick overview. The package main features are:

  • fast time-to-first-plot (~1 sec);

  • extremely concise yet meaningful syntax, makes it ideal for interactive data exploration;

  • no need to learn new API functions or keywords: only two macros (@gp for 2D plots, @gsp for 3D plots) and a basic knowledge of gnuplot are enough to generate most plots;

  • transparent interface between Julia and gnuplot to exploit all functionalities of the latter, both present and future ones;

  • availability of all the palettes from ColorSchemes;

  • support for multiple plots in one window, multiple plotting windows, as well as ASCII and Sixel plots (to plot directly in a terminal);

  • support for histograms (both 1D and 2D);

  • enhanced support for contour plots;

  • export to a huge number of formats such as pdf, png, $\LaTeX$, svg, etc. (actually all those supported by gnuplot);

  • save sessions into gnuplot scripts enables easy plot reproducibility and modifications.

If you're unfamiliar with gnuplot have a look at:

Yet another plotting package?

A powerful plotting framework is among the most important tool in the toolbox of any modern scientist and engineer. As such, it is hard to find a single package to fit all needs, and many solutions are indeed available in the Julia ecosystem.

Gnuplot.jl package fills the niche of users who needs:

  1. publication-quality plots, by exploiting the capabilities of a widely used tool such as gnuplot, and its many output formats available;
  2. a well-documented framework, by taking advantage of all the gnuplot documentation, tutorials and examples available on the web;
  3. a fast response, by relying on an external program (rather than on a large Julia code base);
  4. an interactive data exploration framework, by exposing a carefully designed, extremely concise and easy to remember syntax (at least for users with minimal gnuplot knowledge);
  5. a procedure to foster plot reproducibility by sharing just the data and commands in the form of gnuplot scripts, rather than the original Julia code.

Unlike other packages Gnuplot.jl is not a pure Julia solution as it depends on an external package to actually generate plots. However, if gnuplot is not available on a given platform, the package could still be used in "dry" mode, and no error for a missing dependency will be raised (see Dry sessions).

The Gnuplot.jl package development follows a minimalistic approach: it is essentially a thin layer to send data and commands to gnuplot. This way all underlying capabilities, both present and future ones, are automatically exposed to Julia user, with no need to implement dedicated wrappers.

The functionalities 1, 2 and 3 listed above are similar to those provided by the Gaston package. Gnuplot.jl also provides features 4 and 5, as well as the minimalistic approach.

Do Gnuplot.jl suits my needs?

Any modern plotting package is able to produce a simple scatter plot, with custom symbols, line styles, colors and axis labels. Indeed, this is exactly the example that is reported in every package documentation (also here: see 2D plots). Still, producing complex and publication-quality plots is not an easy task. As a consequence is also not easy to determine whether a package can cope with the most difficult cases (unless you actually try it out) and a reasonable choice is typically to rely on the size of the user base, the availability of documentation / tutorials, and the possibility to preview complex examples.

Gnuplot.jl aims to be ready for even the most challenging plots by relying on the widely and long lasting used gnuplot application, and by allowing each native feature (both present and future ones) to be immediately available in the Julia language. Moreover, Gnuplot.jl provides a unique syntax specifically aimed to increase productivity while performing interactive data exploration.

Last but not least, have a look at the Gnuplot.jl Examples page.

Notation

In this documentation:

  • Gnuplot.jl refers to the Julia package;
  • gnuplot refers to the gnuplot application.

Table of Contents

+Home · Gnuplot.jl

Gnuplot.jl

A Julia interface to gnuplot.

The Gnuplot.jl package allows easy and fast use of gnuplot as a data visualization tool in Julia. Have a look at Basic usage and Examples for a quick overview. The package main features are:

  • fast time-to-first-plot (~1 sec);

  • extremely concise yet meaningful syntax, makes it ideal for interactive data exploration;

  • no need to learn new API functions or keywords: only two macros (@gp for 2D plots, @gsp for 3D plots) and a basic knowledge of gnuplot are enough to generate most plots;

  • transparent interface between Julia and gnuplot to exploit all functionalities of the latter, both present and future ones;

  • availability of all the palettes from ColorSchemes;

  • support for multiple plots in one window, multiple plotting windows, as well as ASCII and Sixel plots (to plot directly in a terminal);

  • support for histograms (both 1D and 2D);

  • enhanced support for contour plots;

  • export to a huge number of formats such as pdf, png, $\LaTeX$, svg, etc. (actually all those supported by gnuplot);

  • save sessions into gnuplot scripts enables easy plot reproducibility and modifications.

If you're unfamiliar with gnuplot have a look at:

Yet another plotting package?

A powerful plotting framework is among the most important tool in the toolbox of any modern scientist and engineer. As such, it is hard to find a single package to fit all needs, and many solutions are indeed available in the Julia ecosystem.

Gnuplot.jl package fills the niche of users who needs:

  1. publication-quality plots, by exploiting the capabilities of a widely used tool such as gnuplot, and its many output formats available;
  2. a well-documented framework, by taking advantage of all the gnuplot documentation, tutorials and examples available on the web;
  3. a fast response, by relying on an external program (rather than on a large Julia code base);
  4. an interactive data exploration framework, by exposing a carefully designed, extremely concise and easy to remember syntax (at least for users with minimal gnuplot knowledge);
  5. a procedure to foster plot reproducibility by sharing just the data and commands in the form of gnuplot scripts, rather than the original Julia code.

Unlike other packages Gnuplot.jl is not a pure Julia solution as it depends on an external package to actually generate plots. However, if gnuplot is not available on a given platform, the package could still be used in "dry" mode, and no error for a missing dependency will be raised (see Dry sessions).

The Gnuplot.jl package development follows a minimalistic approach: it is essentially a thin layer to send data and commands to gnuplot. This way all underlying capabilities, both present and future ones, are automatically exposed to Julia user, with no need to implement dedicated wrappers.

The functionalities 1, 2 and 3 listed above are similar to those provided by the Gaston package. Gnuplot.jl also provides features 4 and 5, as well as the minimalistic approach.

Do Gnuplot.jl suits my needs?

Any modern plotting package is able to produce a simple scatter plot, with custom symbols, line styles, colors and axis labels. Indeed, this is exactly the example that is reported in every package documentation (also here: see 2D plots). Still, producing complex and publication-quality plots is not an easy task. As a consequence is also not easy to determine whether a package can cope with the most difficult cases (unless you actually try it out) and a reasonable choice is typically to rely on the size of the user base, the availability of documentation / tutorials, and the possibility to preview complex examples.

Gnuplot.jl aims to be ready for even the most challenging plots by relying on the widely and long lasting used gnuplot application, and by allowing each native feature (both present and future ones) to be immediately available in the Julia language. Moreover, Gnuplot.jl provides a unique syntax specifically aimed to increase productivity while performing interactive data exploration.

Last but not least, have a look at the Gnuplot.jl Examples page.

Notation

In this documentation:

  • Gnuplot.jl refers to the Julia package;
  • gnuplot refers to the gnuplot application.

Table of Contents

diff --git a/dev/install/index.html b/dev/install/index.html index 7ce45aa..044f7b3 100644 --- a/dev/install/index.html +++ b/dev/install/index.html @@ -1,5 +1,5 @@ -Installation · Gnuplot.jl

Installation

Prerequisite

In order to use the Gnuplot.jl package you'll need gnuplot (ver. >= 5.0) installed on your system, and its executable available in your path.

If gnuplot is not available in your platform you can still use Gnuplot.jl in "dry" mode (see Dry sessions). In this case a plot can not be generated, but you may still generate Gnuplot scripts.

Package installation

In the Julia REPL type:

julia> ]add Gnuplot

Then hit backspace key to return to Julia REPL.

Check installation

Check execution and version of the underlying gnuplot process:

julia> using Gnuplot
+Installation · Gnuplot.jl

Installation

Prerequisite

In order to use the Gnuplot.jl package you'll need gnuplot (ver. >= 5.0) installed on your system, and its executable available in your path.

If gnuplot is not available in your platform you can still use Gnuplot.jl in "dry" mode (see Dry sessions). In this case a plot can not be generated, but you may still generate Gnuplot scripts.

Package installation

In the Julia REPL type:

julia> ]add Gnuplot

Then hit backspace key to return to Julia REPL.

Check installation

Check execution and version of the underlying gnuplot process:

julia> using Gnuplot
 
 julia> Gnuplot.gpversion()
-v"5.2.0"

Generate the first plot:

julia> @gp 1:9

Test default terminal capabilities:

test_terminal()
+v"5.2.0"

Generate the first plot:

julia> @gp 1:9

Test default terminal capabilities:

test_terminal()
diff --git a/dev/search/index.html b/dev/search/index.html index 56a763c..fa2ba45 100644 --- a/dev/search/index.html +++ b/dev/search/index.html @@ -1,2 +1,2 @@ -Search · Gnuplot.jl

Loading search...

    +Search · Gnuplot.jl

    Loading search...

      diff --git a/dev/search_index.js b/dev/search_index.js index 0a3a5d2..0260e3b 100644 --- a/dev/search_index.js +++ b/dev/search_index.js @@ -1,3 +1,3 @@ var documenterSearchIndex = {"docs": -[{"location":"api/#API-1","page":"API","title":"API","text":"","category":"section"},{"location":"api/#Index-1","page":"API","title":"Index","text":"","category":"section"},{"location":"api/#","page":"API","title":"API","text":"","category":"page"},{"location":"api/#Exported-symbols-1","page":"API","title":"Exported symbols","text":"","category":"section"},{"location":"api/#","page":"API","title":"API","text":"The list of Gnuplot.jl exported symbols is as follows:","category":"page"},{"location":"api/#","page":"API","title":"API","text":"@gp\n@gsp\ncontourlines\ndataset_names\nhist\nlinetypes\npalette\npalette_names\nsave\nsession_names\nstats\nterminals\nterminal\ntest_terminal","category":"page"},{"location":"api/#Gnuplot.@gp","page":"API","title":"Gnuplot.@gp","text":"@gp args...\n\nThe @gp macro, and its companion @gsp for 3D plots, allows to send data and commands to the gnuplot using an extremely concise syntax. The macros accepts any number of arguments, with the following meaning:\n\none, or a group of consecutive, array(s) build up a dataset. The different arrays are accessible as columns 1, 2, etc. from the gnuplot process. The number of required input arrays depends on the chosen plot style (see gnuplot documentation);\na string occurring before a dataset is interpreted as a gnuplot command (e.g. set grid);\na string occurring immediately after a dataset is interpreted as a plot element for the dataset, by which you can specify using clause, with clause, line styles, etc.. All keywords may be abbreviated following gnuplot conventions. Moreover, \"plot\" and \"splot\" can be abbreviated to \"p\" and \"s\" respectively;\nthe special symbol :-, whose meaning is to avoid starting a new plot (if given as first argument), or to avoid immediately running all commands to create the final plot (if given as last argument). Its purpose is to allow splitting one long statement into multiple (shorter) ones;\nany other symbol is interpreted as a session ID;\nan Int (>= 1) is interpreted as the plot destination in a multi-plot session (this specification applies to subsequent arguments, not previous ones);\nan input in the form \"\\$name\"=>(array1, array2, etc...) is interpreted as a named dataset. Note that the dataset name must always start with a \"$\";\nan input in the form keyword=value is interpreted as a keyword/value pair. The accepted keywords and their corresponding gnuplot commands are as follows:\nxrange=[low, high] => \"set xrange [low:high];\nyrange=[low, high] => \"set yrange [low:high];\nzrange=[low, high] => \"set zrange [low:high];\ncbrange=[low, high]=> \"set cbrange[low:high];\nkey=\"...\" => \"set key ...\";\ntitle=\"...\" => \"set title \"...\"\";\nxlabel=\"...\" => \"set xlabel \"...\"\";\nylabel=\"...\" => \"set ylabel \"...\"\";\nzlabel=\"...\" => \"set zlabel \"...\"\";\nxlog=true => set logscale x;\nylog=true => set logscale y;\nzlog=true => set logscale z.\n\nAll Keyword names can be abbreviated as long as the resulting name is unambiguous. E.g. you can use xr=[1,10] in place of xrange=[1,10].\n\n\n\n\n\n","category":"macro"},{"location":"api/#Gnuplot.@gsp","page":"API","title":"Gnuplot.@gsp","text":"@gsp args...\n\nThis macro accepts the same syntax as @gp, but produces a 3D plot instead of a 2D one.\n\n\n\n\n\n","category":"macro"},{"location":"api/#Gnuplot.contourlines","page":"API","title":"Gnuplot.contourlines","text":"contourlines(x::Vector{Float64}, y::Vector{Float64}, h::Matrix{Float64}; cntrparam=\"level auto 10\")\n\nCompute paths of contour lines for 2D data, and return a vector of IsoContourLines object.\n\nArguments:\n\nx, y: Coordinates;\nh: the levels on which iso contour lines are to be calculated\ncntrparam: settings to compute contour line paths (see gnuplot documentation for cntrparam).\n\nExample\n\nx = randn(5000);\ny = randn(5000);\nh = hist(x, y, nbins1=20, nbins2=20);\nclines = contourlines(h.bins1, h.bins2, h.counts, cntrparam=\"levels discrete 15, 30, 45\");\n@gp \"set size ratio -1\"\nfor i in 1:length(clines)\n @gp :- clines[i].data \"w l t '$(clines[i].z)' dt $i\"\nend\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.dataset_names","page":"API","title":"Gnuplot.dataset_names","text":"dataset_names(sid::Symbol)\ndataset_names()\n\nReturn a vector with all dataset names for the sid session. If sid is not provided the default session is considered.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.hist","page":"API","title":"Gnuplot.hist","text":"hist(v::Vector{T}; range=extrema(v), bs=NaN, nbins=0, pad=true) where T <: Number\n\nCalculates the histogram of the values in v and returns a Histogram1D structure.\n\nArguments\n\nv: a vector of values to compute the histogra;\nrange: values of the left edge of the first bin and of the right edge of the last bin;\nbs: size of histogram bins;\nnbins: number of bins in the histogram;\npad: if true add one dummy bins with zero counts before the first bin and after the last.\n\nIf bs is given nbins is ignored.\n\nExample\n\nv = randn(1000)\nh = hist(v, bs=0.5)\n@gp h # preview\n@gp h.bins h.counts \"w histep notit\"\n\n\n\n\n\nhist(v1::Vector{T1 <: Number}, v2::Vector{T2 <: Number}; range1=[NaN,NaN], bs1=NaN, nbins1=0, range2=[NaN,NaN], bs2=NaN, nbins2=0)\n\nCalculates the 2D histogram of the values in v1 and v2 and returns a Histogram2D structure.\n\nArguments\n\nv1: a vector of values along the first dimension;\nv2: a vector of values along the second dimension;\nrange1: values of the left edge of the first bin and of the right edge of the last bin, along the first dimension;\nrange1: values of the left edge of the first bin and of the right edge of the last bin, along the second dimension;\nbs1: size of histogram bins along the first dimension;\nbs2: size of histogram bins along the second dimension;\nnbins1: number of bins along the first dimension;\nnbins2: number of bins along the second dimension;\n\nIf bs1 (bs2) is given nbins1 (nbins2) is ignored.\n\nExample\n\nv1 = randn(1000)\nv2 = randn(1000)\nh = hist(v1, v2, bs1=0.5, bs2=0.5)\n@gp h # preview\n@gp \"set size ratio -1\" \"set auto fix\" h.bins1 h.bins2 h.counts \"w image notit\"\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.linetypes","page":"API","title":"Gnuplot.linetypes","text":"linetypes(cmap::ColorScheme)\nlinetypes(s::Symbol)\n\nConvert a ColorScheme object into a string containing the gnuplot commands to set up linetype colors.\n\nIf the argument is a Symbol it is interpreted as the name of one of the predefined schemes in ColorSchemes.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.palette","page":"API","title":"Gnuplot.palette","text":"palette(cmap::ColorScheme)\npalette(s::Symbol)\n\nConvert a ColorScheme object into a string containing the gnuplot commands to set up the corresponding palette.\n\nIf the argument is a Symbol it is interpreted as the name of one of the predefined schemes in ColorSchemes.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.palette_names","page":"API","title":"Gnuplot.palette_names","text":"palette_names()\n\nReturn a vector with all available color schemes for the palette and linetypes function.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.save","page":"API","title":"Gnuplot.save","text":"save(sid::Symbol; term=\"\", output=\"\")\nsave(sid::Symbol, script_filename::String, ;term=\"\", output=\"\")\nsave(; term=\"\", output=\"\")\nsave(script_filename::String ;term=\"\", output=\"\")\n\nExport a (multi-)plot into the external file name provided in the output= keyword. The gnuplot terminal to use is provided through the term= keyword.\n\nIf the script_filename argument is provided a gnuplot script will be written in place of the output image. The latter can then be used in a pure gnuplot session (Julia is no longer needed) to generate exactly the same original plot.\n\nIf the sid argument is provided the operation applies to the corresponding session.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.session_names","page":"API","title":"Gnuplot.session_names","text":"session_names()\n\nReturn a vector with all currently active sessions.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.stats","page":"API","title":"Gnuplot.stats","text":"stats(sid::Symbol,name::String)\nstats(name::String)\nstats(sid::Symbol)\nstats()\n\nPrint a statistical summary for the name dataset, belonging to sid session. If name is not provdied a summary is printed for each dataset in the session. If sid is not provided the default session is considered.\n\nThis function is actually a wrapper for the gnuplot command stats.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.terminals","page":"API","title":"Gnuplot.terminals","text":"terminals()\n\nReturn a Vector{String} with the names of all the available gnuplot terminals.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.terminal","page":"API","title":"Gnuplot.terminal","text":"terminal(sid::Symbol)\nterminal()\n\nReturn a String with the current gnuplot terminal (and its options) of the process associated to session sid, or to the default session (if sid is not provided).\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.test_terminal","page":"API","title":"Gnuplot.test_terminal","text":"test_terminal(term=nothing; linetypes=nothing, palette=nothing)\n\nRun the test and test palette commands on a gnuplot terminal.\n\nIf no term is given it will use the default terminal. If linetypes and palette are given they are used as input to the linetypes and palette function repsetcively to load the associated color scheme.\n\nExamples\n\ntest_terminal()\ntest_terminal(\"wxt\", linetypes=:rust, palette=:viridis)\n\n\n\n\n\n","category":"function"},{"location":"api/#Non-exported-symbols-1","page":"API","title":"Non-exported symbols","text":"","category":"section"},{"location":"api/#","page":"API","title":"API","text":"The following functions are not exported by the Gnuplot.jl package since they are typically not used in every day work, or aimed to debugging purposes. Still, they can be useful in some case, hence they are documented here.","category":"page"},{"location":"api/#","page":"API","title":"API","text":"In order to call these functions you should add the Gnuplot. prefix to the function name.","category":"page"},{"location":"api/#","page":"API","title":"API","text":"Gnuplot.Histogram1D\nGnuplot.Histogram2D\nGnuplot.IsoContourLines\nGnuplot.Options\nGnuplot.Path2d\nGnuplot.exec\nGnuplot.gpversion\nGnuplot.quit\nGnuplot.quitall\nGnuplot.version","category":"page"},{"location":"api/#Gnuplot.Histogram1D","page":"API","title":"Gnuplot.Histogram1D","text":"Histogram1D\n\nA 1D histogram data.\n\nFields\n\nbins::Vector{Float64}: middle points of the bins;\ncounts::Vector{Float64}: couts in the bins;\nbinsize::Float64: size of each bin;\n\n\n\n\n\n","category":"type"},{"location":"api/#Gnuplot.Histogram2D","page":"API","title":"Gnuplot.Histogram2D","text":"Histogram2D\n\nA 2D histogram data.\n\nFields\n\nbins1::Vector{Float64}: middle points of the bins along first dimension;\nbins2::Vector{Float64}: middle points of the bins along second dimension;\ncounts::Vector{Float64}: couts in the bins;\nbinsize1::Float64: size of each bin along first dimension;\nbinsize2::Float64: size of each bin along second dimension;\n\n\n\n\n\n","category":"type"},{"location":"api/#Gnuplot.IsoContourLines","page":"API","title":"Gnuplot.IsoContourLines","text":"IsoContourLines\n\nCoordinates of all contour lines of a given level.\n\nFields\n\npaths::Vector{Path2d}: vector of Path2d objects, one for each continuous path;\ndata::Vector{String}: vector with string representation of all paths (ready to be sent to gnuplot);\nz::Float64: level of the contour lines.\n\n\n\n\n\n","category":"type"},{"location":"api/#Gnuplot.Options","page":"API","title":"Gnuplot.Options","text":"Options\n\nStructure containing the package global options, accessible through Gnuplot.options.\n\nFields\n\ndry::Bool: whether to use dry sessions, i.e. without an underlying Gnuplot process (default: false)\ncmd::String: command to start the Gnuplot process (default: \"gnuplot\")\ndefault::Symbol: default session name (default: :default)\ninit::Vector{String}: commands to initialize the gnuplot session (e.g., to set default terminal)\nverbose::Bool: verbosity flag (default: false)\npreferred_format::Symbol: preferred format to send data to gnuplot. Value must be one of:\nbin: fastest solution for large datasets, but uses temporary files;\ntext: may be slow for large datasets, but no temporary file is involved;\nauto (default) automatically choose the best strategy.\n\n\n\n\n\n","category":"type"},{"location":"api/#Gnuplot.Path2d","page":"API","title":"Gnuplot.Path2d","text":"Path2d\n\nA path in 2D.\n\nFields\n\nx::Vector{Float64}\ny::Vector{Float64}\n\n\n\n\n\n","category":"type"},{"location":"api/#Gnuplot.exec","page":"API","title":"Gnuplot.exec","text":"Gnuplot.exec(sid::Symbol, command::String)\nGnuplot.exec(command::String)\n\nExecute the gnuplot command command on the underlying gnuplot process of the sid session, and return the results as a Vector{String}. If a gnuplot error arises it is propagated as an ErrorException.\n\nThe the sid argument is not provided, the default session is considered.\n\nExamples:\n\nGnuplot.exec(\"print GPVAL_TERM\")\nGnuplot.exec(\"plot sin(x)\")\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.gpversion","page":"API","title":"Gnuplot.gpversion","text":"Gnuplot.gpversion()\n\nReturn the gnuplot application version.\n\nRaise an error if version is < 5.0 (required to use data blocks).\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.quit","page":"API","title":"Gnuplot.quit","text":"Gnuplot.quit(sid::Symbol)\n\nQuit the session identified by sid and the associated gnuplot process (if any).\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.quitall","page":"API","title":"Gnuplot.quitall","text":"Gnuplot.quitall()\n\nQuit all the sessions and the associated gnuplot processes.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.version","page":"API","title":"Gnuplot.version","text":"Gnuplot.version()\n\nReturn the Gnuplot.jl package version.\n\n\n\n\n\n","category":"function"},{"location":"basic/#Basic-usage-1","page":"Basic usage","title":"Basic usage","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The main purpose of the Gnuplot.jl package is to send data and commands to the underlying gnuplot process, in order to generate plots. Unlike other packages, however, the actual commands to plot, or the plot attributes, are not specified through function calls. This is what makes Gnuplot.jl easy to learn and use: there are no functions or keywords names to memorize[1].","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The most important symbols exported by the package are the @gp (for 2D plots) and @gsp (for 3D plots) macros, both accepting any number of arguments, and whose meaning is interpreted as follows:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"one, or a group of consecutive, array(s) build up a dataset. The different arrays are accessible as columns 1, 2, etc. from the gnuplot process. The number of required input arrays depends on the chosen plot style (see gnuplot documentation);\na string occurring before a dataset is interpreted as a gnuplot command (e.g. set grid);\na string occurring immediately after a dataset is interpreted as a plot element for the dataset, by which you can specify using clause, with clause, line styles, etc.;\nthe special symbol :-, whose meaning is to avoid starting a new plot (if given as first argument), or to avoid immediately running all commands to create the final plot (if given as last argument). Its purpose is to allow splitting one long statement into multiple (shorter) ones.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The above list shows all the fundamental concepts to follow the examples presented below. The @gp and @gsp macros also accepts further arguments, but their use will be discussed in Advanced techniques.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"[1]: a previous knowledge of gnuplot usage is, nevertheless, required.","category":"page"},{"location":"basic/#plots2d-1","page":"Basic usage","title":"2D plots","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Here we will show a few examples to generate 2D plots. The examples are intentionally very simple to highlight the behavior of Gnuplot.jl. See Examples for more complex ones.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Remember to run:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"using Gnuplot","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"before running the examples.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"using Gnuplot\nGnuplot.quitall()\nmkpath(\"assets\")\nGnuplot.splash(\"assets/logo.png\")\nsaveas(file) = save(term=\"pngcairo size 480,360\", output=\"assets/$(file).png\")\nempty!(Gnuplot.options.init)\nGnuplot.exec(\"set term unknown\")","category":"page"},{"location":"basic/#Simple-examples-involving-just-gnuplot-commands:-1","page":"Basic usage","title":"Simple examples involving just gnuplot commands:","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Plot-a-sinusoid:-1","page":"Basic usage","title":"Plot a sinusoid:","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp \"plot sin(x)\"\nsaveas(\"ex001\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Plot-two-curves:-1","page":"Basic usage","title":"Plot two curves:","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp \"set key left\" \"plot sin(x)\" \"pl cos(x)\"\nsaveas(\"ex002\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"note: Note\nNote that all gnuplot commands can be abbreviated as long as the resulting string is not ambiguous. In the example above we used pl in place of plot.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Split-a-@gp-call-in-three-statements:-1","page":"Basic usage","title":"Split a @gp call in three statements:","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp \"set grid\" :-\n@gp :- \"p sin(x)\" :-\n@gp :- \"plo cos(x)\"\nsaveas(\"ex003\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#Send-data-from-Julia-to-gnuplot:-1","page":"Basic usage","title":"Send data from Julia to gnuplot:","text":"","category":"section"},{"location":"basic/#Plot-a-parabola-1","page":"Basic usage","title":"Plot a parabola","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp (1:20).^2\nsaveas(\"ex004\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Plot-a-parabola-with-scaled-x-axis,-lines-and-legend-1","page":"Basic usage","title":"Plot a parabola with scaled x axis, lines and legend","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"x = 1:20\n@gp \"set key left\" x ./ 20 x.^2 \"with lines tit 'Parabola'\"\nsaveas(\"ex005\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Multiple-datasets,-logarithmic-axis,-labels-and-colors,-etc.-1","page":"Basic usage","title":"Multiple datasets, logarithmic axis, labels and colors, etc.","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"x = 1:0.1:10\n@gp \"set grid\" \"set key left\" \"set logscale y\"\n@gp :- \"set title 'Plot title'\" \"set label 'X label'\" \"set xrange [0:*]\"\n@gp :- x x.^0.5 \"w l tit 'Pow 0.5' dt 2 lw 2 lc rgb 'red'\"\n@gp :- x x \"w l tit 'Pow 1' dt 1 lw 3 lc rgb 'blue'\"\n@gp :- x x.^2 \"w l tit 'Pow 2' dt 3 lw 2 lc rgb 'purple'\"\nsaveas(\"ex006\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"note: Note\nThe above example lacks the trailing :- symbol. This means the plot will be updated at each command, adding one curve at a time.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Keywords-for-common-commands-1","page":"Basic usage","title":"Keywords for common commands","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"In order to avoid typing long, and very frequently used gnuplot commands, Gnuplot.jl provides a few keywords which can be used in both @gp and @sgp calls:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"xrange=[low, high] => \"set xrange [low:high];\nyrange=[low, high] => \"set yrange [low:high];\nzrange=[low, high] => \"set zrange [low:high];\ncbrange=[low, high]=> \"set cbrange[low:high];\nkey=\"...\" => \"set key ...\";\ntitle=\"...\" => \"set title \\\"...\\\"\";\nxlabel=\"...\" => \"set xlabel \\\"...\\\"\";\nylabel=\"...\" => \"set ylabel \\\"...\\\"\";\nzlabel=\"...\" => \"set zlabel \\\"...\\\"\";\nxlog=true => set logscale x;\nylog=true => set logscale y;\nzlog=true => set logscale z;","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"All such keywords can be abbreviated to unambiguous names.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"By using the above keywords the first lines of the previous example:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp \"set grid\" \"set key left\" \"set logscale y\"\n@gp :- \"set title 'Plot title'\" \"set label 'X label'\" \"set xrange [0:*]\"","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"can be replaced with a shorter version:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp \"set grid\" k=\"left\" ylog=true\n@gp :- tit=\"Plot title\" xlab=\"X label\" xr=[0,NaN]","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"where NaN in the xrange keyword means using axis autoscaling.","category":"page"},{"location":"basic/#Plot-images-1","page":"Basic usage","title":"Plot images","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Gnuplot.jl can also display images, i.e. 2D arrays:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"img = randn(Float64, 30, 50)\nimg[10,:] .= -5\n@gp img \"w image notit\"\nsaveas(\"ex007a\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Note that the first index in the img matrix corresponds to the x coordinate when the image is displayed.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"If the orientation is not the correct one you may adjust it with the gnuplot rotate= keyword (the following example requires the TestImages package to be installed):","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"using TestImages\nimg = testimage(\"lighthouse\");\n@gp \"set size square\" \"set autoscale fix\" img \"rotate=-90deg with rgbimage notit\"\nsaveas(\"ex007b\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"To display a gray image use with image in place of with rgbimage, e.g.:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"img = testimage(\"walkbridge\");\n@gp palette(:lapaz) \"set size square\" \"set autoscale fix\" img \"rotate=-0.5pi with image notit\"\nsaveas(\"ex007c\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Note that we used a custom palette (:lapaz, see Palettes and line types) and the rotation angle has been expressed in radians (-0.5pi).","category":"page"},{"location":"basic/#plots3d-1","page":"Basic usage","title":"3D plots","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"3D plots follow the same rules as 2D ones, just replace the @gp macro with @gsp and add the required columns (according to the plotting style).","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"E.g., to plot a spiral increasing in size along the X direction:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"x = 0:0.1:10pi\n@gsp cbr=[-1,1].*30 x sin.(x) .* x cos.(x) .* x x./20 \"w p pt 7 ps var lc pal\"\nsaveas(\"ex008\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Note that the fourth array in the dataset, x./20, is used as by gnuplot as point size (ps var). Also note that all the keywords discussed above can also be used in 3D plots.","category":"page"},{"location":"basic/#Palettes-and-line-types-1","page":"Basic usage","title":"Palettes and line types","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The Gnuplot.jl package comes with all the ColorSchemes palettes readily available.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"A gnuplot-compliant palette can be retrieved with palette(), and used as any other command. The previous example may use an alternative palette with:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"x = 0:0.1:10pi\n@gsp palette(:viridis) cbr=[-1,1].*30 :-\n@gsp :- x sin.(x) .* x cos.(x) .* x x./20 \"w p pt 7 ps var lc pal\"\nsaveas(\"ex008a\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The ColorSchemes palettes can also be used to generate line types (actually just line colors), by means of the linetypes() function, e.g.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp linetypes(:deepsea)\nx = 1:0.1:4pi\nfor i in 1:5\n @gp :- x i.* sin.(x) \"w l notit lw 5\"\nend\nsaveas(\"ex009\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The list of all available palette can be retrieved with palette_names():","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"palette_names()","category":"page"},{"location":"basic/#Exporting-plots-to-files-1","page":"Basic usage","title":"Exporting plots to files","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The save() function allows to export all plots (as well as multiplots, see Multiplot) to a file using one of the many available gnuplot terminals. To check which terminals are available in your platform type set term in your gnuplot terminal.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"All plots in this page have been saved with:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"save(term=\"pngcairo size 480,360\", output=\"assets/output.png\")","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"except the Lena image, saved with the jpeg terminal:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"save(term=\"jpeg size 480,360\", output=\"assets/output.png\")","category":"page"},{"location":"basic/#Gnuplot-scripts-1","page":"Basic usage","title":"Gnuplot scripts","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Besides exporting plots in a file Gnuplot.jl can also save a script, i.e. a file containing the minimum set of data and commands required to generate a plot within gnuplot.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"To generate a script for one of the example above use:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"save(\"script.gp\")","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"after the plot has been displayed. The script can then be used within a gnuplot session as follows:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"gunplot> load 'script.gp'","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"to generate a plot identical to the original one, without using the Julia language.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The purpose of gnuplot scripts is to allow sharing all data, alongside a plot, in order to foster collaboration among scientists and replicability of results. Moreover, a script can be used at any time to change the details of a plot, without the need to re-run the Julia code used to generate it the first time.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Finally, the scripts are the only possible output when Dry sessions are used (i.e. when gnuplot is not available in the user platform.","category":"page"},{"location":"examples/#Examples-1","page":"Examples","title":"Examples","text":"","category":"section"},{"location":"examples/#","page":"Examples","title":"Examples","text":"An exhaustive gallery of example is available here:","category":"page"},{"location":"examples/#","page":"Examples","title":"Examples","text":"https://lazarusa.github.io/gnuplot-examples/","category":"page"},{"location":"examples/#","page":"Examples","title":"Examples","text":"Further gnuplot examples can be found here: http://www.gnuplotting.org/","category":"page"},{"location":"advanced/#Advanced-techniques-1","page":"Advanced techniques","title":"Advanced techniques","text":"","category":"section"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"Here we will show a few advanced techniques for data visualization using Gnuplot.jl.","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"using Gnuplot\nGnuplot.quitall()\nmkpath(\"assets\")\nsaveas(file) = save(term=\"pngcairo size 480,360\", output=\"assets/$(file).png\")\nempty!(Gnuplot.options.init)\nGnuplot.exec(\"set term unknown\")","category":"page"},{"location":"advanced/#Named-datasets-1","page":"Advanced techniques","title":"Named datasets","text":"","category":"section"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"A dataset may have an associated name whose purpose is to use it multiple times for plotting, while sending it only once to gnuplot. A dataset name must begin with a $.","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"A named dataset is defined as a Pair{String, Tuple}, e.g.:","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"\"\\$name\" => (1:10,)","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"and can be used as an argument to both @gp and gsp, e.g.:","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"x = range(-2pi, stop=2pi, length=100);\ny = sin.(x)\nname = \"\\$MyDataSet1\"\n@gp name=>(x, y) \"plot $name w l lc rgb 'black'\" \"pl $name u 1:(-1.5*\\$2) w l lc rgb 'red'\"\nsaveas(\"ex010\") # hide","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"(Image: )","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"Both curves use the same input data, but the red curve has the second column (\\$2, corresponding to the y value) is multiplied by a factor -1.5.","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"A named dataset comes in hand also when using gnuplot to fit experimental data to a model, e.g.:","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"# Generate data and some noise to simulate measurements\nx = range(-2pi, stop=2pi, length=20);\ny = 1.5 * sin.(0.3 .+ 0.7x);\nerr = 0.1 * maximum(abs.(y)) .* fill(1, size(x));\ny += err .* randn(length(x));\nname = \"\\$MyDataSet1\"\n\n@gp \"f(x) = a * sin(b + c*x)\" :- # define an analytical model\n@gp :- \"a=1\" \"b=1\" \"c=1\" :- # set parameter initial values\n@gp :- name=>(x, y, err) :- # define a named dataset\n@gp :- \"fit f(x) $name via a, b, c;\" # fit the data","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"The parameter best fit values can be retrieved as follows:","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"@info(\"Best fit values:\",\na=Gnuplot.exec(\"print a\"),\nb=Gnuplot.exec(\"print b\"),\nc=Gnuplot.exec(\"print c\"))","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"A named dataset is available until the session is reset, i.e. as long as :- is used as first argument to @gp.","category":"page"},{"location":"advanced/#Multiplot-1","page":"Advanced techniques","title":"Multiplot","text":"","category":"section"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"Gnuplot.jl can draw multiple plots in the same figure by exploiting the multiplot command. Each plot is identified by a positive integer number, which can be used as argument to @gp to redirect commands to the appropriate plot.","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"Continuing previous example we can plot both data and best fit model (in plot 1) and residuals (in plot 2):","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"@gp :- \"set multiplot layout 2,1\"\n@gp :- 1 \"p $name w errorbars t 'Data'\" \n@gp :- \"p $name u 1:(f(\\$1)) w l t 'Best fit model'\"\n@gp :- 2 \"p $name u 1:((f(\\$1)-\\$2) / \\$3):(1) w errorbars t 'Resid. [{/Symbol s}]'\"\n@gp :- [extrema(x)...] [0,0] \"w l notit dt 2 lc rgb 'black'\" # reference line\nsaveas(\"ex011\") # hide","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"(Image: )","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"Note that the order of the plots is not relevant, i.e. we would get the same results with:","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"@gp :- \"set multiplot layout 2,1\"\n@gp :- 2 \"p $name u 1:((f(\\$1)-\\$2) / \\$3):(1) w errorbars t 'Resid. [{/Symbol s}]'\"\n@gp :- [extrema(x)...] [0,0] \"w l notit dt 2 lc rgb 'black'\" # reference line\n@gp :- 1 \"p $name w errorbars t 'Data'\" \n@gp :- \"p $name u 1:(f(\\$1)) w l t 'Best fit model'\"","category":"page"},{"location":"advanced/#Mixing-2D-and-3D-plots-1","page":"Advanced techniques","title":"Mixing 2D and 3D plots","text":"","category":"section"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"A multiplot can also mix 2D and 3D plots:","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"x = y = -10:0.33:10\n@gp \"set multiplot layout 1,2\"\n\n# 2D\n@gp :- 1 x sin.(x) ./ x \"w l notit\"\n\n# 3D\nsinc2d(x,y) = sin.(sqrt.(x.^2 + y.^2))./sqrt.(x.^2+y.^2)\nfxy = [sinc2d(x,y) for x in x, y in y]\n@gsp :- 2 x y fxy \"w pm3d notit\"\nsaveas(\"ex012\") # hide","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"(Image: )","category":"page"},{"location":"advanced/#Multiple-sessions-1","page":"Advanced techniques","title":"Multiple sessions","text":"","category":"section"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"Gnuplot.jl can handle multiple sessions, i.e. multiple gnuplot processes running simultaneously. Each session is identified by a symbol.","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"In order to redirect commands to a specific session simply insert a symbol into your @gp or @gsp call, e.g.:","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"@gp :GP1 \"plot sin(x)\" # opens first window\n@gp :GP2 \"plot sin(x)\" # opens secondo window\n@gp :- :GP1 \"plot cos(x)\" # add a plot on first window","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"If the session ID is not specified the :default session is considered.","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"The names of all current sessions can be retrieved with session_names():","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"println(session_names())","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"To quit a specific session use Gnuplot.quit():","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"Gnuplot.quit(:GP1)","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"The output value is the exit status of the underlying gnuplot process.","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"You may also quit all active sessions at once with Gnuplot.quitall():","category":"page"},{"location":"advanced/#","page":"Advanced techniques","title":"Advanced techniques","text":"Gnuplot.quitall()","category":"page"},{"location":"advanced/#Histograms-(1D)-1","page":"Advanced techniques","title":"Histograms (1D)","text":"","category":"section"},{"location":"advanced/#Histograms-(2D)-1","page":"Advanced techniques","title":"Histograms (2D)","text":"","category":"section"},{"location":"advanced/#Contour-lines-1","page":"Advanced techniques","title":"Contour lines","text":"","category":"section"},{"location":"advanced/#Animations-1","page":"Advanced techniques","title":"Animations","text":"","category":"section"},{"location":"advanced/#Dry-sessions-1","page":"Advanced techniques","title":"Dry sessions","text":"","category":"section"},{"location":"advanced/#Options-1","page":"Advanced techniques","title":"Options","text":"","category":"section"},{"location":"install/#Installation-1","page":"Installation","title":"Installation","text":"","category":"section"},{"location":"install/#Prerequisite-1","page":"Installation","title":"Prerequisite","text":"","category":"section"},{"location":"install/#","page":"Installation","title":"Installation","text":"In order to use the Gnuplot.jl package you'll need gnuplot (ver. >= 5.0) installed on your system, and its executable available in your path.","category":"page"},{"location":"install/#","page":"Installation","title":"Installation","text":"If gnuplot is not available in your platform you can still use Gnuplot.jl in \"dry\" mode (see Dry sessions). In this case a plot can not be generated, but you may still generate Gnuplot scripts.","category":"page"},{"location":"install/#Package-installation-1","page":"Installation","title":"Package installation","text":"","category":"section"},{"location":"install/#","page":"Installation","title":"Installation","text":"In the Julia REPL type:","category":"page"},{"location":"install/#","page":"Installation","title":"Installation","text":"julia> ]add Gnuplot","category":"page"},{"location":"install/#","page":"Installation","title":"Installation","text":"Then hit backspace key to return to Julia REPL.","category":"page"},{"location":"install/#Check-installation-1","page":"Installation","title":"Check installation","text":"","category":"section"},{"location":"install/#","page":"Installation","title":"Installation","text":"Check execution and version of the underlying gnuplot process:","category":"page"},{"location":"install/#","page":"Installation","title":"Installation","text":"using Gnuplot\nGnuplot.gpversion()","category":"page"},{"location":"install/#","page":"Installation","title":"Installation","text":"Generate the first plot:","category":"page"},{"location":"install/#","page":"Installation","title":"Installation","text":"julia> @gp 1:9","category":"page"},{"location":"install/#","page":"Installation","title":"Installation","text":"Test default terminal capabilities:","category":"page"},{"location":"install/#","page":"Installation","title":"Installation","text":"test_terminal()","category":"page"},{"location":"#Gnuplot.jl-1","page":"Home","title":"Gnuplot.jl","text":"","category":"section"},{"location":"#A-Julia-interface-to-gnuplot.-1","page":"Home","title":"A Julia interface to gnuplot.","text":"","category":"section"},{"location":"#","page":"Home","title":"Home","text":"The Gnuplot.jl package allows easy and fast use of gnuplot as a data visualization tool in Julia. Have a look at Basic usage and Examples for a quick overview. The package main features are:","category":"page"},{"location":"#","page":"Home","title":"Home","text":"fast time-to-first-plot (~1 sec);\nextremely concise yet meaningful syntax, makes it ideal for interactive data exploration;\nno need to learn new API functions or keywords: only two macros (@gp for 2D plots, @gsp for 3D plots) and a basic knowledge of gnuplot are enough to generate most plots;\ntransparent interface between Julia and gnuplot to exploit all functionalities of the latter, both present and future ones;\navailability of all the palettes from ColorSchemes;\nsupport for multiple plots in one window, multiple plotting windows, as well as ASCII and Sixel plots (to plot directly in a terminal);\nsupport for histograms (both 1D and 2D);\nenhanced support for contour plots;\nexport to a huge number of formats such as pdf, png, LaTeX, svg, etc. (actually all those supported by gnuplot);\nsave sessions into gnuplot scripts enables easy plot reproducibility and modifications.","category":"page"},{"location":"#","page":"Home","title":"Home","text":"If you're unfamiliar with gnuplot have a look at:","category":"page"},{"location":"#","page":"Home","title":"Home","text":"Main gnuplot site\ngnuplot FAQ","category":"page"},{"location":"#Yet-another-plotting-package?-1","page":"Home","title":"Yet another plotting package?","text":"","category":"section"},{"location":"#","page":"Home","title":"Home","text":"A powerful plotting framework is among the most important tool in the toolbox of any modern scientist and engineer. As such, it is hard to find a single package to fit all needs, and many solutions are indeed available in the Julia ecosystem.","category":"page"},{"location":"#","page":"Home","title":"Home","text":"Gnuplot.jl package fills the niche of users who needs:","category":"page"},{"location":"#","page":"Home","title":"Home","text":"publication-quality plots, by exploiting the capabilities of a widely used tool such as gnuplot, and its many output formats available;\na well-documented framework, by taking advantage of all the gnuplot documentation, tutorials and examples available on the web;\na fast response, by relying on an external program (rather than on a large Julia code base);\nan interactive data exploration framework, by exposing a carefully designed, extremely concise and easy to remember syntax (at least for users with minimal gnuplot knowledge);\na procedure to foster plot reproducibility by sharing just the data and commands in the form of gnuplot scripts, rather than the original Julia code.","category":"page"},{"location":"#","page":"Home","title":"Home","text":"Unlike other packages Gnuplot.jl is not a pure Julia solution as it depends on an external package to actually generate plots. However, if gnuplot is not available on a given platform, the package could still be used in \"dry\" mode, and no error for a missing dependency will be raised (see Dry sessions).","category":"page"},{"location":"#","page":"Home","title":"Home","text":"The Gnuplot.jl package development follows a minimalistic approach: it is essentially a thin layer to send data and commands to gnuplot. This way all underlying capabilities, both present and future ones, are automatically exposed to Julia user, with no need to implement dedicated wrappers.","category":"page"},{"location":"#","page":"Home","title":"Home","text":"The functionalities 1, 2 and 3 listed above are similar to those provided by the Gaston package. Gnuplot.jl also provides features 4 and 5, as well as the minimalistic approach.","category":"page"},{"location":"#Do-Gnuplot.jl-suits-my-needs?-1","page":"Home","title":"Do Gnuplot.jl suits my needs?","text":"","category":"section"},{"location":"#","page":"Home","title":"Home","text":"Any modern plotting package is able to produce a simple scatter plot, with custom symbols, line styles, colors and axis labels. Indeed, this is exactly the example that is reported in every package documentation (also here: see 2D plots). Still, producing complex and publication-quality plots is not an easy task. As a consequence is also not easy to determine whether a package can cope with the most difficult cases (unless you actually try it out) and a reasonable choice is typically to rely on the size of the user base, the availability of documentation / tutorials, and the possibility to preview complex examples.","category":"page"},{"location":"#","page":"Home","title":"Home","text":"Gnuplot.jl aims to be ready for even the most challenging plots by relying on the widely and long lasting used gnuplot application, and by allowing each native feature (both present and future ones) to be immediately available in the Julia language. Moreover, Gnuplot.jl provides a unique syntax specifically aimed to increase productivity while performing interactive data exploration.","category":"page"},{"location":"#","page":"Home","title":"Home","text":"Last but not least, have a look at the Gnuplot.jl Examples page.","category":"page"},{"location":"#Notation-1","page":"Home","title":"Notation","text":"","category":"section"},{"location":"#","page":"Home","title":"Home","text":"In this documentation:","category":"page"},{"location":"#","page":"Home","title":"Home","text":"Gnuplot.jl refers to the Julia package;\ngnuplot refers to the gnuplot application.","category":"page"},{"location":"#Table-of-Contents-1","page":"Home","title":"Table of Contents","text":"","category":"section"},{"location":"#","page":"Home","title":"Home","text":"Pages = [\"index.md\", \"install.md\", \"basic.md\", \"advanced.md\", \"examples.md\", \"api.md\"]","category":"page"},{"location":"tips/#Tips-1","page":"Tips","title":"Tips","text":"","category":"section"},{"location":"tips/#","page":"Tips","title":"Tips","text":"This page collects useful tips in using Gnuplot.jl.","category":"page"},{"location":"tips/#Which-terminal-should-I-use-?-1","page":"Tips","title":"Which terminal should I use ?","text":"","category":"section"},{"location":"tips/#","page":"Tips","title":"Tips","text":"Gnuplot provides dozens of terminals to display and export plots. Here we report a few tips on how to exploit the most used terminals.","category":"page"},{"location":"tips/#wxt-and-qt-1","page":"Tips","title":"wxt and qt","text":"","category":"section"},{"location":"tips/#Mouse-interactions-1","page":"Tips","title":"Mouse interactions","text":"","category":"section"},{"location":"tips/#dumb-and-sixelgd-1","page":"Tips","title":"dumb and sixelgd","text":"","category":"section"},{"location":"tips/#cairopng-1","page":"Tips","title":"cairopng","text":"","category":"section"},{"location":"tips/#gif-1","page":"Tips","title":"gif","text":"","category":"section"},{"location":"tips/#","page":"Tips","title":"Tips","text":"see Animations.","category":"page"},{"location":"tips/#pdf-1","page":"Tips","title":"pdf","text":"","category":"section"},{"location":"tips/#latex-and-cairolatex-1","page":"Tips","title":"latex and cairolatex","text":"","category":"section"},{"location":"tips/#unknown-1","page":"Tips","title":"unknown","text":"","category":"section"},{"location":"tips/#","page":"Tips","title":"Tips","text":"This is a dummy terminal, it produces no output. It is mainly used for debugging purposes.","category":"page"}] +[{"location":"api/#API-1","page":"API","title":"API","text":"","category":"section"},{"location":"api/#Index-1","page":"API","title":"Index","text":"","category":"section"},{"location":"api/#","page":"API","title":"API","text":"","category":"page"},{"location":"api/#Exported-symbols-1","page":"API","title":"Exported symbols","text":"","category":"section"},{"location":"api/#","page":"API","title":"API","text":"The list of Gnuplot.jl exported symbols is as follows:","category":"page"},{"location":"api/#","page":"API","title":"API","text":"@gp\n@gsp\nboxxyerror\ncontourlines\ndataset_names\ngpexec\nhist\nlinetypes\npalette\npalette_names\nsave\nsession_names\nstats\nterminals\nterminal\ntest_terminal","category":"page"},{"location":"api/#Gnuplot.@gp","page":"API","title":"Gnuplot.@gp","text":"@gp args...\n\nThe @gp macro, and its companion @gsp for 3D plots, allows to send data and commands to the gnuplot using an extremely concise syntax. The macros accepts any number of arguments, with the following meaning:\n\none, or a group of consecutive, array(s) build up a dataset. The different arrays are accessible as columns 1, 2, etc. from the gnuplot process. The number of required input arrays depends on the chosen plot style (see gnuplot documentation);\na string occurring before a dataset is interpreted as a gnuplot command (e.g. set grid);\na string occurring immediately after a dataset is interpreted as a plot element for the dataset, by which you can specify using clause, with clause, line styles, etc.. All keywords may be abbreviated following gnuplot conventions. Moreover, \"plot\" and \"splot\" can be abbreviated to \"p\" and \"s\" respectively;\nthe special symbol :-, whose meaning is to avoid starting a new plot (if given as first argument), or to avoid immediately running all commands to create the final plot (if given as last argument). Its purpose is to allow splitting one long statement into multiple (shorter) ones;\nany other symbol is interpreted as a session ID;\nan Int (>= 1) is interpreted as the plot destination in a multi-plot session (this specification applies to subsequent arguments, not previous ones);\nan input in the form \"\\$name\"=>(array1, array2, etc...) is interpreted as a named dataset. Note that the dataset name must always start with a \"$\";\nan input in the form keyword=value is interpreted as a keyword/value pair. The accepted keywords and their corresponding gnuplot commands are as follows:\nxrange=[low, high] => \"set xrange [low:high];\nyrange=[low, high] => \"set yrange [low:high];\nzrange=[low, high] => \"set zrange [low:high];\ncbrange=[low, high]=> \"set cbrange[low:high];\nkey=\"...\" => \"set key ...\";\ntitle=\"...\" => \"set title \"...\"\";\nxlabel=\"...\" => \"set xlabel \"...\"\";\nylabel=\"...\" => \"set ylabel \"...\"\";\nzlabel=\"...\" => \"set zlabel \"...\"\";\nxlog=true => set logscale x;\nylog=true => set logscale y;\nzlog=true => set logscale z.\n\nAll Keyword names can be abbreviated as long as the resulting name is unambiguous. E.g. you can use xr=[1,10] in place of xrange=[1,10].\n\n\n\n\n\n","category":"macro"},{"location":"api/#Gnuplot.@gsp","page":"API","title":"Gnuplot.@gsp","text":"@gsp args...\n\nThis macro accepts the same syntax as @gp, but produces a 3D plot instead of a 2D one.\n\n\n\n\n\n","category":"macro"},{"location":"api/#Gnuplot.boxxyerror","page":"API","title":"Gnuplot.boxxyerror","text":"boxxyerror(x, y; xmin=NaN, ymin=NaN, xmax=NaN, ymax=NaN, cartesian=false)\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.contourlines","page":"API","title":"Gnuplot.contourlines","text":"contourlines(x::Vector{Float64}, y::Vector{Float64}, h::Matrix{Float64}; cntrparam=\"level auto 10\")\n\nCompute paths of contour lines for 2D data, and return a vector of IsoContourLines object.\n\nArguments:\n\nx, y: Coordinates;\nh: the levels on which iso contour lines are to be calculated\ncntrparam: settings to compute contour line paths (see gnuplot documentation for cntrparam).\n\nExample\n\nx = randn(5000);\ny = randn(5000);\nh = hist(x, y, nbins1=20, nbins2=20);\nclines = contourlines(h.bins1, h.bins2, h.counts, cntrparam=\"levels discrete 15, 30, 45\");\n@gp \"set size ratio -1\"\nfor i in 1:length(clines)\n @gp :- clines[i].data \"w l t '$(clines[i].z)' dt $i\"\nend\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.dataset_names","page":"API","title":"Gnuplot.dataset_names","text":"dataset_names(sid::Symbol)\ndataset_names()\n\nReturn a vector with all dataset names for the sid session. If sid is not provided the default session is considered.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.gpexec","page":"API","title":"Gnuplot.gpexec","text":"gpexec(sid::Symbol, command::String)\ngpexec(command::String)\n\nExecute the gnuplot command command on the underlying gnuplot process of the sid session, and return the results as a Vector{String}. If a gnuplot error arises it is propagated as an ErrorException.\n\nThe the sid argument is not provided, the default session is considered.\n\nExamples:\n\ngpexec(\"print GPVAL_TERM\")\ngpexec(\"plot sin(x)\")\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.hist","page":"API","title":"Gnuplot.hist","text":"hist(v::Vector{T}; range=extrema(v), bs=NaN, nbins=0, pad=true) where T <: Number\n\nCalculates the histogram of the values in v and returns a Histogram1D structure.\n\nArguments\n\nv: a vector of values to compute the histogra;\nrange: values of the left edge of the first bin and of the right edge of the last bin;\nbs: size of histogram bins;\nnbins: number of bins in the histogram;\npad: if true add one dummy bins with zero counts before the first bin and after the last.\n\nIf bs is given nbins is ignored.\n\nExample\n\nv = randn(1000)\nh = hist(v, bs=0.5)\n@gp h # preview\n@gp h.bins h.counts \"w histep notit\"\n\n\n\n\n\nhist(v1::Vector{T1 <: Number}, v2::Vector{T2 <: Number}; range1=[NaN,NaN], bs1=NaN, nbins1=0, range2=[NaN,NaN], bs2=NaN, nbins2=0)\n\nCalculates the 2D histogram of the values in v1 and v2 and returns a Histogram2D structure.\n\nArguments\n\nv1: a vector of values along the first dimension;\nv2: a vector of values along the second dimension;\nrange1: values of the left edge of the first bin and of the right edge of the last bin, along the first dimension;\nrange1: values of the left edge of the first bin and of the right edge of the last bin, along the second dimension;\nbs1: size of histogram bins along the first dimension;\nbs2: size of histogram bins along the second dimension;\nnbins1: number of bins along the first dimension;\nnbins2: number of bins along the second dimension;\n\nIf bs1 (bs2) is given nbins1 (nbins2) is ignored.\n\nExample\n\nv1 = randn(1000)\nv2 = randn(1000)\nh = hist(v1, v2, bs1=0.5, bs2=0.5)\n@gp h # preview\n@gp \"set size ratio -1\" \"set auto fix\" h.bins1 h.bins2 h.counts \"w image notit\"\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.linetypes","page":"API","title":"Gnuplot.linetypes","text":"linetypes(cmap::ColorScheme; rev=false)\nlinetypes(s::Symbol; rev=false)\n\nConvert a ColorScheme object into a string containing the gnuplot commands to set up linetype colors.\n\nIf the argument is a Symbol it is interpreted as the name of one of the predefined schemes in ColorSchemes. If rev=true the line colors are reversed.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.palette","page":"API","title":"Gnuplot.palette","text":"palette(cmap::ColorScheme; rev=false)\npalette(s::Symbol; rev=false)\n\nConvert a ColorScheme object into a string containing the gnuplot commands to set up the corresponding palette.\n\nIf the argument is a Symbol it is interpreted as the name of one of the predefined schemes in ColorSchemes. If rev=true the palette is reversed.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.palette_names","page":"API","title":"Gnuplot.palette_names","text":"palette_names()\n\nReturn a vector with all available color schemes for the palette and linetypes function.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.save","page":"API","title":"Gnuplot.save","text":"save(sid::Symbol; term=\"\", output=\"\")\nsave(sid::Symbol, script_filename::String, ;term=\"\", output=\"\")\nsave(; term=\"\", output=\"\")\nsave(script_filename::String ;term=\"\", output=\"\")\n\nExport a (multi-)plot into the external file name provided in the output= keyword. The gnuplot terminal to use is provided through the term= keyword.\n\nIf the script_filename argument is provided a gnuplot script will be written in place of the output image. The latter can then be used in a pure gnuplot session (Julia is no longer needed) to generate exactly the same original plot.\n\nIf the sid argument is provided the operation applies to the corresponding session.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.session_names","page":"API","title":"Gnuplot.session_names","text":"session_names()\n\nReturn a vector with all currently active sessions.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.stats","page":"API","title":"Gnuplot.stats","text":"stats(sid::Symbol,name::String)\nstats(name::String)\nstats(sid::Symbol)\nstats()\n\nPrint a statistical summary for the name dataset, belonging to sid session. If name is not provdied a summary is printed for each dataset in the session. If sid is not provided the default session is considered.\n\nThis function is actually a wrapper for the gnuplot command stats.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.terminals","page":"API","title":"Gnuplot.terminals","text":"terminals()\n\nReturn a Vector{String} with the names of all the available gnuplot terminals.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.terminal","page":"API","title":"Gnuplot.terminal","text":"terminal(sid::Symbol)\nterminal()\n\nReturn a String with the current gnuplot terminal (and its options) of the process associated to session sid, or to the default session (if sid is not provided).\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.test_terminal","page":"API","title":"Gnuplot.test_terminal","text":"test_terminal(term=nothing; linetypes=nothing, palette=nothing)\n\nRun the test and test palette commands on a gnuplot terminal.\n\nIf no term is given it will use the default terminal. If lt and pal are given they are used as input to the linetypes and palette function repsetcively to load the associated color scheme.\n\nExamples\n\ntest_terminal()\ntest_terminal(\"wxt\", lt=:rust, pal=:viridis)\n\n\n\n\n\n","category":"function"},{"location":"api/#Non-exported-symbols-1","page":"API","title":"Non-exported symbols","text":"","category":"section"},{"location":"api/#","page":"API","title":"API","text":"The following functions are not exported by the Gnuplot.jl package since they are typically not used in every day work, or aimed to debugging purposes. Still, they can be useful in some case, hence they are documented here.","category":"page"},{"location":"api/#","page":"API","title":"API","text":"In order to call these functions you should add the Gnuplot. prefix to the function name.","category":"page"},{"location":"api/#","page":"API","title":"API","text":"Gnuplot.Histogram1D\nGnuplot.Histogram2D\nGnuplot.IsoContourLines\nGnuplot.Options\nGnuplot.Path2d\nGnuplot.gpversion\nGnuplot.quit\nGnuplot.quitall\nGnuplot.version","category":"page"},{"location":"api/#Gnuplot.Histogram1D","page":"API","title":"Gnuplot.Histogram1D","text":"Histogram1D\n\nA 1D histogram data.\n\nFields\n\nbins::Vector{Float64}: bin center values;\ncounts::Vector{Float64}: counts in the bins;\nbinsize::Float64: size of each bin;\n\n\n\n\n\n","category":"type"},{"location":"api/#Gnuplot.Histogram2D","page":"API","title":"Gnuplot.Histogram2D","text":"Histogram2D\n\nA 2D histogram data.\n\nFields\n\nbins1::Vector{Float64}: bin center values along first dimension;\nbins2::Vector{Float64}: bin center values along second dimension;\ncounts::Vector{Float64}: counts in the bins;\nbinsize1::Float64: size of each bin along first dimension;\nbinsize2::Float64: size of each bin along second dimension;\n\n\n\n\n\n","category":"type"},{"location":"api/#Gnuplot.IsoContourLines","page":"API","title":"Gnuplot.IsoContourLines","text":"IsoContourLines\n\nCoordinates of all contour lines of a given level.\n\nFields\n\npaths::Vector{Path2d}: vector of Path2d objects, one for each continuous path;\ndata::Vector{String}: vector with string representation of all paths (ready to be sent to gnuplot);\nz::Float64: level of the contour lines.\n\n\n\n\n\n","category":"type"},{"location":"api/#Gnuplot.Options","page":"API","title":"Gnuplot.Options","text":"Options\n\nStructure containing the package global options, accessible through Gnuplot.options.\n\nFields\n\ndry::Bool: whether to use dry sessions, i.e. without an underlying Gnuplot process (default: false)\ncmd::String: command to start the Gnuplot process (default: \"gnuplot\")\ndefault::Symbol: default session name (default: :default)\ninit::Vector{String}: commands to initialize the gnuplot session (e.g., to set default terminal)\nverbose::Bool: verbosity flag (default: false)\npreferred_format::Symbol: preferred format to send data to gnuplot. Value must be one of:\nbin: fastest solution for large datasets, but uses temporary files;\ntext: may be slow for large datasets, but no temporary file is involved;\nauto (default) automatically choose the best strategy.\n\n\n\n\n\n","category":"type"},{"location":"api/#Gnuplot.Path2d","page":"API","title":"Gnuplot.Path2d","text":"Path2d\n\nA path in 2D.\n\nFields\n\nx::Vector{Float64}\ny::Vector{Float64}\n\n\n\n\n\n","category":"type"},{"location":"api/#Gnuplot.gpversion","page":"API","title":"Gnuplot.gpversion","text":"Gnuplot.gpversion()\n\nReturn the gnuplot application version.\n\nRaise an error if version is < 5.0 (required to use data blocks).\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.quit","page":"API","title":"Gnuplot.quit","text":"Gnuplot.quit(sid::Symbol)\n\nQuit the session identified by sid and the associated gnuplot process (if any).\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.quitall","page":"API","title":"Gnuplot.quitall","text":"Gnuplot.quitall()\n\nQuit all the sessions and the associated gnuplot processes.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.version","page":"API","title":"Gnuplot.version","text":"Gnuplot.version()\n\nReturn the Gnuplot.jl package version.\n\n\n\n\n\n","category":"function"},{"location":"basic/#Basic-usage-1","page":"Basic usage","title":"Basic usage","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The main purpose of the Gnuplot.jl package is to send data and commands to the underlying gnuplot process, in order to generate plots. Unlike other packages, however, the actual commands to plot, or the plot attributes, are not specified through function calls. This is what makes Gnuplot.jl easy to learn and use: there are no functions or keywords names to memorize[1].","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The most important symbols exported by the package are the @gp (for 2D plots) and @gsp (for 3D plots) macros, both accepting any number of arguments, and whose meaning is interpreted as follows:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"one, or a group of consecutive, array(s) build up a dataset. The different arrays are accessible as columns 1, 2, etc. from the gnuplot process. The number of required input arrays depends on the chosen plot style (see gnuplot documentation);\na string occurring before a dataset is interpreted as a gnuplot command (e.g. set grid);\na string occurring immediately after a dataset is interpreted as a plot element for the dataset, by which you can specify using clause, with clause, line styles, etc.;\nthe special symbol :-, whose meaning is to avoid starting a new plot (if given as first argument), or to avoid immediately running all commands to create the final plot (if given as last argument). Its purpose is to allow splitting one long statement into multiple (shorter) ones.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The above list shows all the fundamental concepts to follow the examples presented below. The @gp and @gsp macros also accepts further arguments, but their use will be discussed in Advanced usage.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"[1]: a previous knowledge of gnuplot usage is, nevertheless, required.","category":"page"},{"location":"basic/#plots2d-1","page":"Basic usage","title":"2D plots","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Here we will show a few examples to generate 2D plots. The examples are intentionally very simple to highlight the behavior of Gnuplot.jl. See Examples for more complex ones.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Remember to run:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"using Gnuplot","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"before running the examples.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"using Gnuplot\nGnuplot.quitall()\nmkpath(\"assets\")\nGnuplot.splash(\"assets/logo.png\")\nsaveas(file) = save(term=\"pngcairo size 480,360 fontscale 0.8\", output=\"assets/$(file).png\")\nempty!(Gnuplot.options.init)\ngpexec(\"set term unknown\")","category":"page"},{"location":"basic/#Simple-examples-involving-just-gnuplot-commands:-1","page":"Basic usage","title":"Simple examples involving just gnuplot commands:","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Plot-a-sinusoid:-1","page":"Basic usage","title":"Plot a sinusoid:","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp \"plot sin(x)\"\nsaveas(\"ex001\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Plot-two-curves:-1","page":"Basic usage","title":"Plot two curves:","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp \"set key left\" \"plot sin(x)\" \"pl cos(x)\"\nsaveas(\"ex002\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"note: Note\nNote that all gnuplot commands can be abbreviated as long as the resulting string is not ambiguous. In the example above we used pl in place of plot.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Split-a-@gp-call-in-three-statements:-1","page":"Basic usage","title":"Split a @gp call in three statements:","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp \"set grid\" :-\n@gp :- \"p sin(x)\" :-\n@gp :- \"plo cos(x)\"\nsaveas(\"ex003\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#Send-data-from-Julia-to-gnuplot:-1","page":"Basic usage","title":"Send data from Julia to gnuplot:","text":"","category":"section"},{"location":"basic/#Plot-a-parabola-1","page":"Basic usage","title":"Plot a parabola","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp (1:20).^2\nsaveas(\"ex004\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Plot-a-parabola-with-scaled-x-axis,-lines-and-legend-1","page":"Basic usage","title":"Plot a parabola with scaled x axis, lines and legend","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"x = 1:20\n@gp \"set key left\" x ./ 20 x.^2 \"with lines tit 'Parabola'\"\nsaveas(\"ex005\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Multiple-datasets,-logarithmic-axis,-labels-and-colors,-etc.-1","page":"Basic usage","title":"Multiple datasets, logarithmic axis, labels and colors, etc.","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"x = 1:0.1:10\n@gp \"set grid\" \"set key left\" \"set logscale y\"\n@gp :- \"set title 'Plot title'\" \"set label 'X label'\" \"set xrange [0:*]\"\n@gp :- x x.^0.5 \"w l tit 'Pow 0.5' dt 2 lw 2 lc rgb 'red'\"\n@gp :- x x \"w l tit 'Pow 1' dt 1 lw 3 lc rgb 'blue'\"\n@gp :- x x.^2 \"w l tit 'Pow 2' dt 3 lw 2 lc rgb 'purple'\"\nsaveas(\"ex006\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"note: Note\nThe above example lacks the trailing :- symbol. This means the plot will be updated at each command, adding one curve at a time.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Keywords-for-common-commands-1","page":"Basic usage","title":"Keywords for common commands","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"In order to avoid typing long, and very frequently used gnuplot commands, Gnuplot.jl provides a few keywords which can be used in both @gp and @sgp calls:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"xrange=[low, high] => \"set xrange [low:high];\nyrange=[low, high] => \"set yrange [low:high];\nzrange=[low, high] => \"set zrange [low:high];\ncbrange=[low, high]=> \"set cbrange[low:high];\nkey=\"...\" => \"set key ...\";\ntitle=\"...\" => \"set title \\\"...\\\"\";\nxlabel=\"...\" => \"set xlabel \\\"...\\\"\";\nylabel=\"...\" => \"set ylabel \\\"...\\\"\";\nzlabel=\"...\" => \"set zlabel \\\"...\\\"\";\nxlog=true => set logscale x;\nylog=true => set logscale y;\nzlog=true => set logscale z;","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"All such keywords can be abbreviated to unambiguous names.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"By using the above keywords the first lines of the previous example:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp \"set grid\" \"set key left\" \"set logscale y\"\n@gp :- \"set title 'Plot title'\" \"set label 'X label'\" \"set xrange [0:*]\"","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"can be replaced with a shorter version:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp \"set grid\" k=\"left\" ylog=true\n@gp :- tit=\"Plot title\" xlab=\"X label\" xr=[0,NaN]","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"where NaN in the xrange keyword means using axis autoscaling.","category":"page"},{"location":"basic/#Plot-images-1","page":"Basic usage","title":"Plot images","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Gnuplot.jl can also display images, i.e. 2D arrays:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"img = randn(Float64, 30, 50)\nimg[10,:] .= -5\n@gp img \"w image notit\"\nsaveas(\"ex007a\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Note that the first index in the img matrix corresponds to the x coordinate when the image is displayed.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"If the orientation is not the correct one you may adjust it with the gnuplot rotate= keyword (the following example requires the TestImages package to be installed):","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"using TestImages\nimg = testimage(\"lighthouse\");\n@gp \"set size square\" \"set autoscale fix\" img \"rotate=-90deg with rgbimage notit\"\nsaveas(\"ex007b\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"To display a gray image use with image in place of with rgbimage, e.g.:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"img = testimage(\"walkbridge\");\n@gp palette(:lapaz) \"set size square\" \"set autoscale fix\" img \"rotate=-0.5pi with image notit\"\nsaveas(\"ex007c\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Note that we used a custom palette (:lapaz, see Palettes and line types) and the rotation angle has been expressed in radians (-0.5pi).","category":"page"},{"location":"basic/#plots3d-1","page":"Basic usage","title":"3D plots","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"3D plots follow the same rules as 2D ones, just replace the @gp macro with @gsp and add the required columns (according to the plotting style).","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"E.g., to plot a spiral increasing in size along the X direction:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"x = 0:0.1:10pi\n@gsp cbr=[-1,1].*30 x sin.(x) .* x cos.(x) .* x x./20 \"w p pt 7 ps var lc pal\"\nsaveas(\"ex008\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Note that the fourth array in the dataset, x./20, is used as by gnuplot as point size (ps var). Also note that all the keywords discussed above can also be used in 3D plots.","category":"page"},{"location":"basic/#Palettes-and-line-types-1","page":"Basic usage","title":"Palettes and line types","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The Gnuplot.jl package comes with all the ColorSchemes palettes readily available.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"A gnuplot-compliant palette can be retrieved with palette(), and used as any other command. The previous example may use an alternative palette with:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"x = 0:0.1:10pi\n@gsp palette(:viridis) cbr=[-1,1].*30 :-\n@gsp :- x sin.(x) .* x cos.(x) .* x x./20 \"w p pt 7 ps var lc pal\"\nsaveas(\"ex008a\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The ColorSchemes palettes can also be used to generate line types (actually just line colors), by means of the linetypes() function, e.g.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp linetypes(:deepsea)\nx = 1:0.1:4pi\nfor i in 1:5\n @gp :- x i.* sin.(x) \"w l notit lw 5\"\nend\nsaveas(\"ex009\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The list of all available palette can be retrieved with palette_names():","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"palette_names()","category":"page"},{"location":"basic/#Exporting-plots-to-files-1","page":"Basic usage","title":"Exporting plots to files","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Gnuplot.jl to export all plots (as well as multiplots, see Multiplot) to an external file using one of the many available gnuplot terminals. To check which terminals are available in your platform type:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"terminals()","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(see also terminal() to check your current terminal).","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Once you choose the proper terminal (i.e. format of the exported file), use the save() function to export. As an example, all the plots in this page have been saved with:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"save(term=\"pngcairo size 480,360 fontscale 0.8\", output=\"assets/output.png\")","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Note that you can pass both the terminal name and its options via the term= keyword. See Gnuplot terminals for further info on the terminals.","category":"page"},{"location":"basic/#Gnuplot-scripts-1","page":"Basic usage","title":"Gnuplot scripts","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Besides exporting plots in a file Gnuplot.jl can also save a script, i.e. a file containing the minimum set of data and commands required to re-create a figure using just gnuplot.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"To generate a script for one of the example above use:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"save(\"script.gp\")","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"after the plot has been displayed. Note that when images or large datasets are involved, save() may store the data in binary files under a directory named

      Gnuplot terminals

      Gnuplot provides dozens of terminals to display plots or export them into files (see terminals() to get a list of enabled terminals on your platform). This section discuss a few tips on how to use the most common terminals.

      To use a specific terminal for interactive use you may either add it as initialization command for all new session with (see Options):

      push!(Gnuplot.options.init, "set term wxt")

      or directly send the command to a specific session (see Direct command execution)

      gpexec("set term wxt")

      See official gnuplot documentation for further info on terminals and their options.

      Interactive terminals (wxt and qt)

      The multiplatform wxt and qt terminals are among the most widely used ones for their nicely looking outputs on display and for their interactive capabilities.

      You may set them as terminal with:

      "set term wxt size 800,600"

      or

      "set term qt  size 800,600"

      (the size 800,600 is optional and can be omitted).

      Press the h key on the window to display an help message with all available keyboard shortcuts. In particular press 6 to enable printing plot coordinates on Julia stdout (ensure mouse is enabled with m).

      Plot in a terminal application (dumb, sixel and sixelgd)

      Gnuplot supports plotting in a terminal application, with no need for X11 or other GUI support, via the dumb, sixel and sixelgd terminals. These are extremely useful when you run Julia on a remote shell through ssh, with no X11 forwarding. You may set these terminals with one of the following command:

      "set term dumb"
      +"set term sixel"
      +"set term sixelgd"

      The dumb terminal uses ASCII characters to draw a plot, while sixel and sixelgd actually use bitmaps (but require Sixel support to be enabled in the terminal, e.g. xterm -ti vt340). A sixel plot on xterm looks as follows:

      The above terminals are available if gnuplot has been compiled with the --with-bitmap-terminals option enabled and Libgd (only for sixelgd).

      Export to image files

      Gnuplot provides dozens of terminals able to export on files. Examples are:

      • cairopng to export PNG files;
      • pdfcairo for PDF;
      • jpeg for JPG;
      • gif for GIF (see Animations).

      All the above terminals support the size and fontscale options to quickly adjust the size of the rasterized image and the size of the font respectively. E.g.:

      save(term="pngcairo size 480,360 fontscale 0.8", output="output.png")

      (see also save()).

      Gnuplot is also able to export vector (i.e. non-raster) plots through the svg terminal.

      The cairolatex terminal

      The cairolatex terminal allows to produce high quality plots by splitting the output into a PDF file (containing a rasterized image of a plot) and a .tex file (containing all the text as $\LaTeX$ code). The following example shows how to write plot tics and an equation in $\LaTeX$:

      x = LinRange(-2pi, 2pi, 1000)
      +@gp t="Polynomial approximation of sin(x)"  "set style fill transparent solid 0.6 noborder"
      +@gp :- raw"""set xtics ('$-\pi$' -pi, '$-\pi/2$' -pi/2, 0, '$\pi/2$' pi/2, '$\pi$' pi)"""
      +@gp :- xr=3.8.*[-1, 1] yr=[-1.5,1.5] key="box opaque left horiz" linetypes(:Blues_3) "set grid front"
      +latex = raw"""\begin{minipage}[c]{\textwidth}\begin{equation*}""" *
      +	raw"""\sin(x) = \sum_0^{+\infty} \frac{(-1)^n}{(2n + 1)!} x^{2n+1}""" * 
      +	raw"""\end{equation*} \end{minipage}"""
      +@gp :- "set label at graph 0.62,0.2 front center '$latex'"
      +approx = fill(0., length(x));
      +@gp :- x sin.(x) approx .+= x           "w filledcurve t 'n=0' lt 1"
      +@gp :- x sin.(x) approx .+= -x.^3/6     "w filledcurve t 'n=1' lt 2"
      +@gp :- x sin.(x) approx .+=  x.^5/120   "w filledcurve t 'n=2' lt 3"
      +@gp :- x sin.(x) approx .+= -x.^7/5040  "w filledcurve t 'n=3' lt 4"
      +@gp :- x sin.(x)                        "w l t 'sin(x)' lw 2 lc rgb 'black'"
      +save(term="cairolatex pdf input color dashed size 5in,3.3in", output="test.tex")
      Warning

      If you add a path in the output= keyword this will also be copied in the the .tex file. I suggest to use just filenames, with no path, in order to avoid possible errors when compiling $\LaTeX$ code.

      The two output files (test.tex and test.pdf) can then be included in a $\LaTeX$ file as follows:

      \documentclass{article}
      +\usepackage{amsmath}
      +\usepackage{graphicx}
      +\usepackage{color}
      +
      +\begin{document}
      +\begin{figure}
      +  \input{test.tex}
      +\end{figure}
      +\end{document}

      And the output is: