diff --git a/dev/advanced/index.html b/dev/advanced/index.html index f3e4126..79719f7 100644 --- a/dev/advanced/index.html +++ b/dev/advanced/index.html @@ -1,5 +1,5 @@ -Advanced techniques · Gnuplot.jl

Advanced techniques

Multiplot

Mixing 2D and 3D plots


+Advanced techniques · Gnuplot.jl
+

Multiple processes

Named datasets

Histograms (1D)

Histograms (2D)

Contour lines

Animations

Dry sessions

Options

diff --git a/dev/api/index.html b/dev/api/index.html index c66cb84..5f4870a 100644 --- a/dev/api/index.html +++ b/dev/api/index.html @@ -1,5 +1,5 @@ -API · Gnuplot.jl

API

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

Gnuplot.@gpMacro

@gp args...

The @gp macro (and its companion @gsp, for splot operations) allows to exploit all of the Gnuplot package functionalities using an extremely efficient and concise syntax. Both macros accept the same syntax, as described below.

The macros accepts any number of arguments, with the following meaning:

  • a symbol: the name of the session to use;
  • a string: a command (e.g. "set key left") or plot specification (e.g. "with lines");
  • a string starting with a $ sign: a data set name;
  • an Int > 0: the plot destination in a multiplot session;
  • a keyword/value pair: a keyword value (see below);
  • any other type: a dataset to be passed to Gnuplot. Each dataset must be terminated by either:
    • a string starting with a $ sign (i.e. the data set name);
    • or a string with the plot specifications (e.g. "with lines");
  • the :- symbol, used as first argument, avoids resetting the Gnuplot session. Used as last argument avoids immediate execution of the plot/splot command. This symbol can be used to split a single call into multiple ones.

All entries are optional, and there is no mandatory order. The plot specification can either be:

  • a complete plot/splot command (e.g., "plot sin(x)", both "plot" and "splot" can be abbreviated to "p" and "s" respectively);
  • or a partial specification starting with the "with" clause (if it follows a data set).

The list of accepted keyword is as follows:

  • title::String: plot title;
  • xlabel::String: X axis label;
  • ylabel::String: Y axis label;
  • zlabel::String: Z axis label;
  • xlog::Bool: logarithmic scale for X axis;
  • ylog::Bool: logarithmic scale for Y axis;
  • zlog::Bool: logarithmic scale for Z axis;
  • xrange::NTuple{2, Number}: X axis range;
  • yrange::NTuple{2, Number}: Y axis range;
  • zrange::NTuple{2, Number}: Z axis range;
  • cbrange::NTuple{2, Number}: Color box axis range;

The symbol for the above-mentioned keywords may also be used in a shortened form, as long as there is no ambiguity with other keywords. E.g. you can use: xr=(1,10) in place of xrange=(1,10).

Examples:

Simple examples with no data:

@gp "plot sin(x)"
+API · Gnuplot.jl

API

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

Gnuplot.@gpMacro

@gp args...

The @gp macro (and its companion @gsp, for splot operations) allows to exploit all of the Gnuplot package functionalities using an extremely efficient and concise syntax. Both macros accept the same syntax, as described below.

The macros accepts any number of arguments, with the following meaning:

  • a symbol: the name of the session to use;
  • a string: a command (e.g. "set key left") or plot specification (e.g. "with lines");
  • a string starting with a $ sign: a data set name;
  • an Int > 0: the plot destination in a multiplot session;
  • a keyword/value pair: a keyword value (see below);
  • any other type: a dataset to be passed to Gnuplot. Each dataset must be terminated by either:
    • a string starting with a $ sign (i.e. the data set name);
    • or a string with the plot specifications (e.g. "with lines");
  • the :- symbol, used as first argument, avoids resetting the Gnuplot session. Used as last argument avoids immediate execution of the plot/splot command. This symbol can be used to split a single call into multiple ones.

All entries are optional, and there is no mandatory order. The plot specification can either be:

  • a complete plot/splot command (e.g., "plot sin(x)", both "plot" and "splot" can be abbreviated to "p" and "s" respectively);
  • or a partial specification starting with the "with" clause (if it follows a data set).

The list of accepted keyword is as follows:

  • title::String: plot title;
  • xlabel::String: X axis label;
  • ylabel::String: Y axis label;
  • zlabel::String: Z axis label;
  • xlog::Bool: logarithmic scale for X axis;
  • ylog::Bool: logarithmic scale for Y axis;
  • zlog::Bool: logarithmic scale for Z axis;
  • xrange::NTuple{2, Number}: X axis range;
  • yrange::NTuple{2, Number}: Y axis range;
  • zrange::NTuple{2, Number}: Z axis range;
  • cbrange::NTuple{2, Number}: Color box axis range;

The symbol for the above-mentioned keywords may also be used in a shortened form, as long as there is no ambiguity with other keywords. E.g. you can use: xr=(1,10) in place of xrange=(1,10).

Examples:

Simple examples with no data:

@gp "plot sin(x)"
 @gp "plot sin(x)" "pl cos(x)"
 @gp "plo sin(x)" "s cos(x)"
 
@@ -70,4 +70,4 @@ save(term="pdf", output="gnuplot.pdf")

source
Gnuplot.saveFunction

save(...)

Save the data and commands in the current session to either:

  • the gnuplot process (i.e. produce a plot): save(term="", output="");
  • an IO stream: save(stream::IO; term="", output="");
  • a file: save(file::AbstractStrings; term="", output="").

To save the data and command from a specific session pass the ID as first argument, i.e.:

  • save(sid::Symbol, term="", output="");
  • save(sid::Symbol, file::AbstractStrings; term="", output="").

In all cases the term keyword allows to specify a gnuplot terminal, and the output keyword allows to specify an output file.

source
Missing docstring.

Missing docstring for palette. Check Documenter's build log for details.

Missing docstring.

Missing docstring for linestyles. Check Documenter's build log for details.

Missing docstring.

Missing docstring for hist. Check Documenter's build log for details.

Missing docstring.

Missing docstring for contourlines. Check Documenter's build log for details.

+@gp "set size square" img "u 2:(-\$1):3:4:5 with rgbimage" # Correct orientationsource diff --git a/dev/assets/basic1.png b/dev/assets/basic1.png index 2b6394f..c7d4831 100644 Binary files a/dev/assets/basic1.png and b/dev/assets/basic1.png differ diff --git a/dev/assets/basic2.png b/dev/assets/basic2.png index 08e431e..00168c1 100644 Binary files a/dev/assets/basic2.png and b/dev/assets/basic2.png differ diff --git a/dev/assets/basic3.png b/dev/assets/basic3.png index 550320c..b0a1792 100644 Binary files a/dev/assets/basic3.png and b/dev/assets/basic3.png differ diff --git a/dev/assets/basic4.png b/dev/assets/basic4.png index 2885c2f..31de506 100644 Binary files a/dev/assets/basic4.png and b/dev/assets/basic4.png differ diff --git a/dev/assets/basic5.png b/dev/assets/basic5.png index 4138c47..fffb23d 100644 Binary files a/dev/assets/basic5.png and b/dev/assets/basic5.png differ diff --git a/dev/assets/basic6.png b/dev/assets/basic6.png index 5f1eab4..e967ee7 100644 Binary files a/dev/assets/basic6.png and b/dev/assets/basic6.png differ diff --git a/dev/assets/basic7a.png b/dev/assets/basic7a.png index 02e29f5..75f33e0 100644 Binary files a/dev/assets/basic7a.png and b/dev/assets/basic7a.png differ diff --git a/dev/assets/basic7b.jpg b/dev/assets/basic7b.jpg index 030c9f1..d18289b 100644 Binary files a/dev/assets/basic7b.jpg and b/dev/assets/basic7b.jpg differ diff --git a/dev/assets/basic8.jpg b/dev/assets/basic8.jpg deleted file mode 100644 index 773fe53..0000000 Binary files a/dev/assets/basic8.jpg and /dev/null differ diff --git a/dev/assets/basic8.png b/dev/assets/basic8.png new file mode 100644 index 0000000..77e7141 Binary files /dev/null and b/dev/assets/basic8.png differ diff --git a/dev/assets/basic8a.jpg b/dev/assets/basic8a.jpg deleted file mode 100644 index 65f33e1..0000000 Binary files a/dev/assets/basic8a.jpg and /dev/null differ diff --git a/dev/assets/basic8a.png b/dev/assets/basic8a.png new file mode 100644 index 0000000..fd541d2 Binary files /dev/null and b/dev/assets/basic8a.png differ diff --git a/dev/assets/basic9.jpg b/dev/assets/basic9.jpg deleted file mode 100644 index e0e22d2..0000000 Binary files a/dev/assets/basic9.jpg and /dev/null differ diff --git a/dev/assets/basic9.png b/dev/assets/basic9.png new file mode 100644 index 0000000..9943bc2 Binary files /dev/null and b/dev/assets/basic9.png differ diff --git a/dev/assets/logo.png b/dev/assets/logo.png index 64d40e5..264872b 100644 Binary files a/dev/assets/logo.png and b/dev/assets/logo.png differ diff --git a/dev/basic/index.html b/dev/basic/index.html index 2d54095..256943e 100644 --- a/dev/basic/index.html +++ b/dev/basic/index.html @@ -1,33 +1,22 @@ -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 creating 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 lists all the required 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.

Plots in 2D

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.

Simple examples involving just gnuplot commands:

Plot a sinusoid:

@gp "plot sin(x)"
-save(term="png size 480,360", output="src/assets/basic1.png") # hide


Plot two curves:

@gp "set key left" "plot sin(x)" "pl cos(x)"
-save(term="png size 480,360", output="src/assets/basic2.png") # hide

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 creating 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 lists all the required 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"  :-
 @gp :- "p sin(x)"  :-
-@gp :- "plo cos(x)"
-save(term="png size 480,360", output="src/assets/basic3.png") # hide

Send data from Julia to gnuplot:

Plot a parabola

@gp (1:20).^2 
-save(term="png size 480,360", output="src/assets/basic4.png") # hide


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'"
-save(term="png size 480,360", output="src/assets/basic5.png") # hide


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

x = 1:0.1:10
+@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
 @gp    "set grid" "set key left" "set logscale y"
 @gp :- "set title 'Plot title'" "set label 'X label'" "set xrange [0:12]"
 @gp :- x x.^0.5 "w l tit 'Pow 0.5' dt 2 lw 2 lc rgb 'red'"
 @gp :- x x      "w l tit 'Pow 1'   dt 1 lw 3 lc rgb 'blue'"
-@gp :- x x.^2   "w l tit 'Pow 2'   dt 3 lw 2 lc rgb 'purple'"
-save(term="png size 480,360", output="src/assets/basic6.png") # hide

Note

The above example lacks the trailing :- symbol. This means the plot will be updated at each command, adding one curve at a time.


Keywords for common commands

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:

  • 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 such keywords can be abbreviated to unambiguous names.

By using the above keywords the first lines of the previous example:

@gp    "set grid" "set key left" "set logscale y"
+@gp :- x x.^2   "w l tit 'Pow 2'   dt 3 lw 2 lc rgb 'purple'"

Note

The above example lacks the trailing :- symbol. This means the plot will be updated at each command, adding one curve at a time.


Keywords for common commands

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:

  • 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 such keywords can be abbreviated to unambiguous names.

By using the above keywords the first lines of the previous example:

@gp    "set grid" "set key left" "set logscale y"
 @gp :- "set title 'Plot title'" "set label 'X label'" "set xrange [0:12]"

can be replaced with a shorter version:

@gp    "set grid" k="left" ylog=true
 @gp :- tit="Plot title" xlab="X label" xr=[0,12]

Plot images

Gnuplot.jl can also display images, i.e. 2D arrays:

img = randn(Float64, 30, 50)
 img[10,:] .= -4
-@gp img "w image notit"
-save(term="jpeg size 480,360", output="src/assets/basic7a.png") # hide

Note that the first index corresponds to the X coordinate when the image is displayed.

The following example shows how to fix orientation of an image by means of the using clause (the TestImages package is required to run this example):

using TestImages
+@gp img "w image notit"

Note that the first index corresponds to the X coordinate when the image is displayed.

The following example shows how to fix orientation of an image by means of the using clause (the TestImages package is required to run this example):

using TestImages
 img = testimage("lena");
-@gp "set size square" img "u 2:(-\$1):3:4:5 with rgbimage notit"
-save(term="jpeg size 480,360", output="src/assets/basic7b.jpg") # hide

Plots in 3D

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).

E.g., to plot a spiral increasing in size along the X direction:

x = 0:0.1:10pi
-@gsp x  sin.(x) .* x  cos.(x) .* x  x./15  "w p pt 7 ps var lc pal"
-save(term="jpeg size 640,480", output="src/assets/basic8.jpg") # hide

The keywords discussed above can also be used in 3D plots.

Palettes and line styles

The Gnuplot.jl package comes with all the ColorSchemes palettes readily available.

A gnuplot-compliant palette can be retrieved with palette(), and used as any other command. The previous example may use an alternative palette with:

x = 0:0.1:10pi
-@gsp palette(:viridis) x  sin.(x) .* x  cos.(x) .* x  x./15  "w p pt 7 ps var lc pal"
-save(term="jpeg size 640,480", output="src/assets/basic8a.jpg") # hide

The ColorSchemes palettes can also be used to generate line styles, by means of the linestyles() function, e.g.

@gp linestyles(:deepsea)
+@gp "set size square" "set autoscale fix" img "u 2:(-\$1):3:4:5 with rgbimage notit"

3D plots

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).

E.g., to plot a spiral increasing in size along the X direction:

x = 0:0.1:10pi
+@gsp x  sin.(x) .* x  cos.(x) .* x  x./20  "w p pt 7 ps var lc pal"

The keywords discussed above can also be used in 3D plots.

Palettes and line types

The Gnuplot.jl package comes with all the ColorSchemes palettes readily available.

A gnuplot-compliant palette can be retrieved with palette(), and used as any other command. The previous example may use an alternative palette with:

x = 0:0.1:10pi
+@gsp palette(:viridis) x  sin.(x) .* x  cos.(x) .* x  x./20  "w p pt 7 ps var lc pal"

The ColorSchemes palettes can also be used to generate line types (actually just color attributes), by means of the linetypes() function, e.g.

@gp linetypes(:deepsea)
 x = 1:0.1:4pi
 for i in 1:5
-    @gp :- x i.* sin.(x) "w l notit ls $i lw 5"
-end
-save(term="jpeg size 480,360", output="src/assets/basic9.jpg") # hide

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="png size 480,360", output="output.png")

except the Lena image, saved with the jpeg terminal:

save(term="jpeg size 480,360", output="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.
+ @gp :- x i.* sin.(x) "w l notit lw 5" +end

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.
diff --git a/dev/examples/index.html b/dev/examples/index.html index f854d0d..f2624f2 100644 --- a/dev/examples/index.html +++ b/dev/examples/index.html @@ -1,2 +1,2 @@ -Examples · Gnuplot.jl
+Examples · Gnuplot.jl
diff --git a/dev/index.html b/dev/index.html index 9897cea..4e1f210 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 the most complex plots;

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

  • fast data transmission through system pipes (no temporary files involved);

  • 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.

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 string 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 Plots in 2D). 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 the most complex plots;

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

  • fast data transmission through system pipes (no temporary files involved);

  • 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.

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 string 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 8003f83..e8d6c96 100644 --- a/dev/install/index.html +++ b/dev/install/index.html @@ -1,3 +1,5 @@ -Installation · Gnuplot.jl

Installation

Prerequisite

In order to use the Gnuplot.jl package you'll need gnuplot (ver. >= 4.7) 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()

Generate the first plot:

julia> @gp 1:9
+Installation · Gnuplot.jl

Installation

Prerequisite

In order to use the Gnuplot.jl package you'll need gnuplot (ver. >= 4.7) 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
diff --git a/dev/search/index.html b/dev/search/index.html index 2557023..707fbd6 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 7080d2c..8850648 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/#","page":"API","title":"API","text":"The list of Gnuplot.jl exported symbols are as follows:","category":"page"},{"location":"api/#","page":"API","title":"API","text":"@gp\n@gsp\nsave\npalette\nlinestyles\nhist\ncontourlines","category":"page"},{"location":"api/#Gnuplot.@gp","page":"API","title":"Gnuplot.@gp","text":"@gp args...\n\nThe @gp macro (and its companion @gsp, for splot operations) allows to exploit all of the Gnuplot package functionalities using an extremely efficient and concise syntax. Both macros accept the same syntax, as described below.\n\nThe macros accepts any number of arguments, with the following meaning:\n\na symbol: the name of the session to use;\na string: a command (e.g. \"set key left\") or plot specification (e.g. \"with lines\");\na string starting with a $ sign: a data set name;\nan Int > 0: the plot destination in a multiplot session;\na keyword/value pair: a keyword value (see below);\nany other type: a dataset to be passed to Gnuplot. Each dataset must be terminated by either:\na string starting with a $ sign (i.e. the data set name);\nor a string with the plot specifications (e.g. \"with lines\");\nthe :- symbol, used as first argument, avoids resetting the Gnuplot session. Used as last argument avoids immediate execution of the plot/splot command. This symbol can be used to split a single call into multiple ones.\n\nAll entries are optional, and there is no mandatory order. The plot specification can either be:\n\na complete plot/splot command (e.g., \"plot sin(x)\", both \"plot\" and \"splot\" can be abbreviated to \"p\" and \"s\" respectively);\nor a partial specification starting with the \"with\" clause (if it follows a data set).\n\nThe list of accepted keyword is as follows:\n\ntitle::String: plot title;\nxlabel::String: X axis label;\nylabel::String: Y axis label;\nzlabel::String: Z axis label;\nxlog::Bool: logarithmic scale for X axis;\nylog::Bool: logarithmic scale for Y axis;\nzlog::Bool: logarithmic scale for Z axis;\nxrange::NTuple{2, Number}: X axis range;\nyrange::NTuple{2, Number}: Y axis range;\nzrange::NTuple{2, Number}: Z axis range;\ncbrange::NTuple{2, Number}: Color box axis range;\n\nThe symbol for the above-mentioned keywords may also be used in a shortened form, as long as there is no ambiguity with other keywords. E.g. you can use: xr=(1,10) in place of xrange=(1,10).\n\nExamples:\n\nSimple examples with no data:\n\n@gp \"plot sin(x)\"\n@gp \"plot sin(x)\" \"pl cos(x)\"\n@gp \"plo sin(x)\" \"s cos(x)\"\n\n# Split a `@gp` call in two\n@gp \"plot sin(x)\" :-\n@gp :- \"plot cos(x)\"\n\n# Insert a 3 second pause between one plot and the next\n@gp \"plot sin(x)\" 2 xr=(-2pi,2pi) \"pause 3\" \"plot cos(4*x)\"\n\nSimple examples with data:\n\n@gp \"set key left\" tit=\"My title\" xr=(1,12) 1:10 \"with lines tit 'Data'\"\n\nx = collect(1.:10)\n@gp x\n@gp x x\n@gp x -x\n@gp x x.^2\n@gp x x.^2 \"w l\"\n\nlw = 3\n@gp x x.^2 \"w l lw $lw\"\n\nA more complex example\n\n@gp(\"set grid\", \"set key left\", xlog=true, ylog=true,\n title=\"My title\", xlab=\"X label\", ylab=\"Y label\",\n x, x.^0.5, \"w l tit 'Pow 0.5' dt 2 lw 2 lc rgb 'red'\",\n x, x , \"w l tit 'Pow 1' dt 1 lw 3 lc rgb 'blue'\",\n x, x.^2 , \"w l tit 'Pow 2' dt 3 lw 2 lc rgb 'purple'\")\n\nMultiplot example:\n\n@gp(xr=(-2pi,2pi), \"unset key\",\n \"set multi layout 2,2 title 'Multiplot title'\",\n 1, \"p sin(x)\" ,\n 2, \"p sin(2*x)\",\n 3, \"p sin(3*x)\",\n 4, \"p sin(4*x)\")\n\nor equivalently\n\n@gp xr=(-2pi,2pi) \"unset key\" \"set multi layout 2,2 title 'Multiplot title'\" :-\nfor i in 1:4\n @gp :- i \"p sin($i*x)\" :-\nend\n@gp\n\nMultiple gnuplot sessions\n\n@gp :GP1 \"plot sin(x)\"\n@gp :GP2 \"plot sin(x)\"\n\nGnuplot.quitall()\n\nFurther examples\n\nx = range(-2pi, stop=2pi, length=100);\ny = 1.5 * sin.(0.3 .+ 0.7x) ;\nnoise = randn(length(x))./2;\ne = 0.5 * fill(1, size(x));\n\nname = \"\\$MyDataSet1\"\n@gp x y name \"plot $name w l\" \"pl $name u 1:(2*\\$2) w l\"\n\n@gsp randn(Float64, 30, 50)\n@gp randn(Float64, 30, 50) \"w image\"\n@gsp x y y\n\n@gp(\"set key horizontal\", \"set grid\",\n xrange=(-7,7), ylabel=\"Y label\",\n x, y, \"w l t 'Real model' dt 2 lw 2 lc rgb 'red'\",\n x, y+noise, e, \"w errorbars t 'Data'\")\n\n@gp \"f(x) = a * sin(b + c*x); a = 1; b = 1; c = 1;\" :-\n@gp :- x y+noise e name :-\n@gp :- \"fit f(x) $name u 1:2:3 via a, b, c;\" :-\n@gp :- \"set multiplot layout 2,1\" :-\n@gp :- \"plot $name w points\" ylab=\"Data and model\" :-\n@gp :- \"plot $name u 1:(f(\\$1)) w lines\" :-\n@gp :- 2 xlab=\"X label\" ylab=\"Residuals\" :-\n@gp :- \"plot $name u 1:((f(\\$1)-\\$2) / \\$3):(1) w errorbars notit\"\n\n# Retrieve values for a, b and c\na = Meta.parse(Gnuplot.exec(\"print a\"))\nb = Meta.parse(Gnuplot.exec(\"print b\"))\nc = Meta.parse(Gnuplot.exec(\"print c\"))\n\n# Save to a PDF file\nsave(term=\"pdf\", output=\"gnuplot.pdf\")\n\nDisplay an image\n\nusing TestImages\nimg = testimage(\"lena\");\n@gp img \"w image\"\n@gp \"set size square\" img \"w rgbimage\" # Color image with correct proportions\n@gp \"set size square\" img \"u 2:(-\\$1):3:4:5 with rgbimage\" # Correct orientation\n\n\n\n\n\n","category":"macro"},{"location":"api/#Gnuplot.@gsp","page":"API","title":"Gnuplot.@gsp","text":"@gsp\n\nSee documentation for @gp.\n\n\n\n\n\n","category":"macro"},{"location":"api/#Gnuplot.save","page":"API","title":"Gnuplot.save","text":"save(...)\n\nSave the data and commands in the current session to either:\n\nthe gnuplot process (i.e. produce a plot): save(term=\"\", output=\"\");\nan IO stream: save(stream::IO; term=\"\", output=\"\");\na file: save(file::AbstractStrings; term=\"\", output=\"\").\n\nTo save the data and command from a specific session pass the ID as first argument, i.e.:\n\nsave(sid::Symbol, term=\"\", output=\"\");\nsave(sid::Symbol, file::AbstractStrings; term=\"\", output=\"\").\n\nIn all cases the term keyword allows to specify a gnuplot terminal, and the output keyword allows to specify an output file.\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 creating 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 lists all the required 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/#Plots-in-2D-1","page":"Basic usage","title":"Plots in 2D","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/#Simple-examples-involving-just-gnuplot-commands:-1","page":"Basic usage","title":"Simple examples involving just gnuplot commands:","text":"","category":"section"},{"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)\"\nsave(term=\"png size 480,360\", output=\"src/assets/basic1.png\") # 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)\"\nsave(term=\"png size 480,360\", output=\"src/assets/basic2.png\") # 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)\"\nsave(term=\"png size 480,360\", output=\"src/assets/basic3.png\") # 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 \nsave(term=\"png size 480,360\", output=\"src/assets/basic4.png\") # 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'\"\nsave(term=\"png size 480,360\", output=\"src/assets/basic5.png\") # 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:12]\"\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'\"\nsave(term=\"png size 480,360\", output=\"src/assets/basic6.png\") # 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:12]\"","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,12]","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,:] .= -4\n@gp img \"w image notit\"\nsave(term=\"jpeg size 480,360\", output=\"src/assets/basic7a.png\") # 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 corresponds to the X coordinate when the image is displayed.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The following example shows how to fix orientation of an image by means of the using clause (the TestImages package is required to run this example):","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"using TestImages\nimg = testimage(\"lena\");\n@gp \"set size square\" img \"u 2:(-\\$1):3:4:5 with rgbimage notit\"\nsave(term=\"jpeg size 480,360\", output=\"src/assets/basic7b.jpg\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#Plots-in-3D-1","page":"Basic usage","title":"Plots in 3D","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 x sin.(x) .* x cos.(x) .* x x./15 \"w p pt 7 ps var lc pal\"\nsave(term=\"jpeg size 640,480\", output=\"src/assets/basic8.jpg\") # 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 keywords discussed above can also be used in 3D plots.","category":"page"},{"location":"basic/#Palettes-and-line-styles-1","page":"Basic usage","title":"Palettes and line styles","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) x sin.(x) .* x cos.(x) .* x x./15 \"w p pt 7 ps var lc pal\"\nsave(term=\"jpeg size 640,480\", output=\"src/assets/basic8a.jpg\") # 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 styles, by means of the linestyles() function, e.g.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp linestyles(:deepsea)\nx = 1:0.1:4pi\nfor i in 1:5\n @gp :- x i.* sin.(x) \"w l notit ls $i lw 5\"\nend\nsave(term=\"jpeg size 480,360\", output=\"src/assets/basic9.jpg\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","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=\"png size 480,360\", output=\"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=\"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/#Multiplot-1","page":"Advanced techniques","title":"Multiplot","text":"","category":"section"},{"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":"\n@gp \"set multiplot layout 1,2\"\n@gp :- 1 \"plot sin(x) w l\"\n\n\nx = y = -10:0.33:10\nfz(x,y) = sin.(sqrt.(x.^2 + y.^2))./sqrt.(x.^2+y.^2)\nfxy = [fz(x,y) for x in x, y in y]\n\n@gsp :- 2 x y fxy \"w pm3d notit\"\n","category":"page"},{"location":"advanced/#Multiple-processes-1","page":"Advanced techniques","title":"Multiple processes","text":"","category":"section"},{"location":"advanced/#Named-datasets-1","page":"Advanced techniques","title":"Named datasets","text":"","category":"section"},{"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. >= 4.7) 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":"julia> using Gnuplot\njulia> Gnuplot.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":"#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 the most complex plots;\ntransparent interface between Julia and gnuplot to exploit all functionalities of the latter, both present and future ones;\nfast data transmission through system pipes (no temporary files involved);\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":"#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 string 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 Plots in 2D). 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":"api/#API-1","page":"API","title":"API","text":"","category":"section"},{"location":"api/#","page":"API","title":"API","text":"The list of Gnuplot.jl exported symbols are as follows:","category":"page"},{"location":"api/#","page":"API","title":"API","text":"@gp","category":"page"},{"location":"api/#Gnuplot.@gp","page":"API","title":"Gnuplot.@gp","text":"@gp args...\n\nThe @gp macro (and its companion @gsp, for splot operations) allows to exploit all of the Gnuplot package functionalities using an extremely efficient and concise syntax. Both macros accept the same syntax, as described below.\n\nThe macros accepts any number of arguments, with the following meaning:\n\na symbol: the name of the session to use;\na string: a command (e.g. \"set key left\") or plot specification (e.g. \"with lines\");\na string starting with a $ sign: a data set name;\nan Int > 0: the plot destination in a multiplot session;\na keyword/value pair: a keyword value (see below);\nany other type: a dataset to be passed to Gnuplot. Each dataset must be terminated by either:\na string starting with a $ sign (i.e. the data set name);\nor a string with the plot specifications (e.g. \"with lines\");\nthe :- symbol, used as first argument, avoids resetting the Gnuplot session. Used as last argument avoids immediate execution of the plot/splot command. This symbol can be used to split a single call into multiple ones.\n\nAll entries are optional, and there is no mandatory order. The plot specification can either be:\n\na complete plot/splot command (e.g., \"plot sin(x)\", both \"plot\" and \"splot\" can be abbreviated to \"p\" and \"s\" respectively);\nor a partial specification starting with the \"with\" clause (if it follows a data set).\n\nThe list of accepted keyword is as follows:\n\ntitle::String: plot title;\nxlabel::String: X axis label;\nylabel::String: Y axis label;\nzlabel::String: Z axis label;\nxlog::Bool: logarithmic scale for X axis;\nylog::Bool: logarithmic scale for Y axis;\nzlog::Bool: logarithmic scale for Z axis;\nxrange::NTuple{2, Number}: X axis range;\nyrange::NTuple{2, Number}: Y axis range;\nzrange::NTuple{2, Number}: Z axis range;\ncbrange::NTuple{2, Number}: Color box axis range;\n\nThe symbol for the above-mentioned keywords may also be used in a shortened form, as long as there is no ambiguity with other keywords. E.g. you can use: xr=(1,10) in place of xrange=(1,10).\n\nExamples:\n\nSimple examples with no data:\n\n@gp \"plot sin(x)\"\n@gp \"plot sin(x)\" \"pl cos(x)\"\n@gp \"plo sin(x)\" \"s cos(x)\"\n\n# Split a `@gp` call in two\n@gp \"plot sin(x)\" :-\n@gp :- \"plot cos(x)\"\n\n# Insert a 3 second pause between one plot and the next\n@gp \"plot sin(x)\" 2 xr=(-2pi,2pi) \"pause 3\" \"plot cos(4*x)\"\n\nSimple examples with data:\n\n@gp \"set key left\" tit=\"My title\" xr=(1,12) 1:10 \"with lines tit 'Data'\"\n\nx = collect(1.:10)\n@gp x\n@gp x x\n@gp x -x\n@gp x x.^2\n@gp x x.^2 \"w l\"\n\nlw = 3\n@gp x x.^2 \"w l lw $lw\"\n\nA more complex example\n\n@gp(\"set grid\", \"set key left\", xlog=true, ylog=true,\n title=\"My title\", xlab=\"X label\", ylab=\"Y label\",\n x, x.^0.5, \"w l tit 'Pow 0.5' dt 2 lw 2 lc rgb 'red'\",\n x, x , \"w l tit 'Pow 1' dt 1 lw 3 lc rgb 'blue'\",\n x, x.^2 , \"w l tit 'Pow 2' dt 3 lw 2 lc rgb 'purple'\")\n\nMultiplot example:\n\n@gp(xr=(-2pi,2pi), \"unset key\",\n \"set multi layout 2,2 title 'Multiplot title'\",\n 1, \"p sin(x)\" ,\n 2, \"p sin(2*x)\",\n 3, \"p sin(3*x)\",\n 4, \"p sin(4*x)\")\n\nor equivalently\n\n@gp xr=(-2pi,2pi) \"unset key\" \"set multi layout 2,2 title 'Multiplot title'\" :-\nfor i in 1:4\n @gp :- i \"p sin($i*x)\" :-\nend\n@gp\n\nMultiple gnuplot sessions\n\n@gp :GP1 \"plot sin(x)\"\n@gp :GP2 \"plot sin(x)\"\n\nGnuplot.quitall()\n\nFurther examples\n\nx = range(-2pi, stop=2pi, length=100);\ny = 1.5 * sin.(0.3 .+ 0.7x) ;\nnoise = randn(length(x))./2;\ne = 0.5 * fill(1, size(x));\n\nname = \"\\$MyDataSet1\"\n@gp x y name \"plot $name w l\" \"pl $name u 1:(2*\\$2) w l\"\n\n@gsp randn(Float64, 30, 50)\n@gp randn(Float64, 30, 50) \"w image\"\n@gsp x y y\n\n@gp(\"set key horizontal\", \"set grid\",\n xrange=(-7,7), ylabel=\"Y label\",\n x, y, \"w l t 'Real model' dt 2 lw 2 lc rgb 'red'\",\n x, y+noise, e, \"w errorbars t 'Data'\")\n\n@gp \"f(x) = a * sin(b + c*x); a = 1; b = 1; c = 1;\" :-\n@gp :- x y+noise e name :-\n@gp :- \"fit f(x) $name u 1:2:3 via a, b, c;\" :-\n@gp :- \"set multiplot layout 2,1\" :-\n@gp :- \"plot $name w points\" ylab=\"Data and model\" :-\n@gp :- \"plot $name u 1:(f(\\$1)) w lines\" :-\n@gp :- 2 xlab=\"X label\" ylab=\"Residuals\" :-\n@gp :- \"plot $name u 1:((f(\\$1)-\\$2) / \\$3):(1) w errorbars notit\"\n\n# Retrieve values for a, b and c\na = Meta.parse(Gnuplot.exec(\"print a\"))\nb = Meta.parse(Gnuplot.exec(\"print b\"))\nc = Meta.parse(Gnuplot.exec(\"print c\"))\n\n# Save to a PDF file\nsave(term=\"pdf\", output=\"gnuplot.pdf\")\n\nDisplay an image\n\nusing TestImages\nimg = testimage(\"lena\");\n@gp img \"w image\"\n@gp \"set size square\" img \"w rgbimage\" # Color image with correct proportions\n@gp \"set size square\" img \"u 2:(-\\$1):3:4:5 with rgbimage\" # Correct orientation\n\n\n\n\n\n","category":"macro"},{"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 creating 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 lists all the required 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()\nmkdir(\"assets\")\nGnuplot.splash(\"assets/logo.png\")\nsaveas(file) = save(term=\"pngcairo size 480,360\", output=\"assets/$(file).png\")\nempty!(Gnuplot.options.init)\npush!(Gnuplot.options.init, \"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(\"basic1\") # 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(\"basic2\") # 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(\"basic3\") # 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(\"basic4\") # 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(\"basic5\") # 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:12]\"\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(\"basic6\") # 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:12]\"","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,12]","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,:] .= -4\n@gp img \"w image notit\"\nsaveas(\"basic7a\") # 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 corresponds to the X coordinate when the image is displayed.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The following example shows how to fix orientation of an image by means of the using clause (the TestImages package is required to run this example):","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"using TestImages\nimg = testimage(\"lena\");\n@gp \"set size square\" \"set autoscale fix\" img \"u 2:(-\\$1):3:4:5 with rgbimage notit\"\nsave(term=\"jpeg size 480,360\", output=\"assets/basic7b.jpg\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","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 x sin.(x) .* x cos.(x) .* x x./20 \"w p pt 7 ps var lc pal\"\nsaveas(\"basic8\") # 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 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) x sin.(x) .* x cos.(x) .* x x./20 \"w p pt 7 ps var lc pal\"\nsaveas(\"basic8a\") # 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 color attributes), 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(\"basic9\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","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/#Multiplot-1","page":"Advanced techniques","title":"Multiplot","text":"","category":"section"},{"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":"\n@gp \"set multiplot layout 1,2\"\n@gp :- 1 \"plot sin(x) w l\"\n\n\nx = y = -10:0.33:10\nfz(x,y) = sin.(sqrt.(x.^2 + y.^2))./sqrt.(x.^2+y.^2)\nfxy = [fz(x,y) for x in x, y in y]\n\n@gsp :- 2 x y fxy \"w pm3d notit\"\n","category":"page"},{"location":"advanced/#Multiple-processes-1","page":"Advanced techniques","title":"Multiple processes","text":"","category":"section"},{"location":"advanced/#Named-datasets-1","page":"Advanced techniques","title":"Named datasets","text":"","category":"section"},{"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. >= 4.7) 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":"#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 the most complex plots;\ntransparent interface between Julia and gnuplot to exploit all functionalities of the latter, both present and future ones;\nfast data transmission through system pipes (no temporary files involved);\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":"#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 string 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"}] } diff --git a/dev/tips/index.html b/dev/tips/index.html new file mode 100644 index 0000000..97d62d9 --- /dev/null +++ b/dev/tips/index.html @@ -0,0 +1,2 @@ + +Tips · Gnuplot.jl