Package options and initialization
Options
The package options are stored in a global structure available in Julia as Gnuplot.option (the type of the structure is Gnuplot.Options). The most important settings are as follows:
dry::Bool: if true all new sessions will be started as Dry sessions. Default isfalse, but if the package is not able to start a gnuplot process it will automatically switch totrue;cmd::String: command to start the gnuplot process, default value is"gnuplot". Use this field to specify a custom path to the gnuplot executable;term::String: default terminal for interactive use (default is an empty string, i.e. use gnuplot settings). A custom terminal can be set with, e.g.:
julia> Gnuplot.options.term = "wxt size 700,400";term_svg::String: terminal to save png files (default:"svg background rgb 'white' dynamic");term_png::String: terminal to save png files (default:"pngcairo");init::Vector{String}: commands to initialize the session when it is created or reset. It can be used to, e.g., set a custom linetypes or palette:
julia> push!(Gnuplot.options.init, linetypes(:Set1_5, lw=1.5, ps=1.5));Note that this option affect all the sessions, and that all inserted commands are saved in Gnuplot scripts;
verbose::Bool: a flag to set verbosity of the package. Iftrueall communication with the underlying process will be printed on stdout. E.g.:
julia> Gnuplot.options.verbose = true;
julia> x = 1.:10;
julia> @gp x x.^2 "w l t 'Parabola'"
GNUPLOT (default) unset multiplot
GNUPLOT (default) set output
GNUPLOT (default) reset session
GNUPLOT (default) set term wxt size 700,400
GNUPLOT (default) print GPVAL_TERM
GNUPLOT (default) -> wxt
GNUPLOT (default) print GPVAL_TERMOPTIONS
GNUPLOT (default) -> 0 size 700, 400 enhanced
GNUPLOT (default) set term wxt 0 size 700, 400 enhanced title 'Gnuplot.jl: default'
GNUPLOT (default) $data1 << EOD
GNUPLOT (default) 1.0 1.0
GNUPLOT (default) 2.0 4.0
GNUPLOT (default) 3.0 9.0
GNUPLOT (default) 4.0 16.0
GNUPLOT (default) ...
GNUPLOT (default) EOD
GNUPLOT (default)
GNUPLOT (default) reset
GNUPLOT (default) plot \
$data1 w l t 'Parabola'
julia> save(term="pngcairo size 480,360 fontscale 0.8", output="output.png")
GNUPLOT (default) reset
GNUPLOT (default) print GPVAL_TERM
GNUPLOT (default) -> wxt
GNUPLOT (default) print GPVAL_TERMOPTIONS
GNUPLOT (default) -> 0 title "Gnuplot.jl: default" size 700, 400 enhanced
GNUPLOT (default) set term pngcairo size 480,360 fontscale 0.8
GNUPLOT (default) set output 'output.png'
GNUPLOT (default) plot \
$data1 w l t 'Parabola'
GNUPLOT (default) set output
GNUPLOT (default) set term wxt 0 title "Gnuplot.jl: default" size 700, 400 enhancedEach line reports the package name (GNUPLOT), the session name (default), the command or string being sent to gnuplot process, and the returned response (line starting with ->). Default value is false;
Jupyter and Juno
Gnuplot.jl can display plots in Jupyter and Juno by exporting images in the PNG and SVG formats. To customize the terminals used to export the images set the term_png or term_svg fields of the Gnuplot.Options structure, e.g.:
julia> Gnuplot.options.term_png = "pngcairo size 700,400 linewidth 2";
julia> Gnuplot.options.term_svg = "svg dynamic";Package initialization
If you use Gnuplot.jl frequently you may find convenient to collect all the package settings (see Options) in a single place, to quickly recall them in a Julia session. I suggest to put the following code in the ~/.julia/config/startup.jl initialization file (further info here):
macro gnuplotrc()
return :(
using Revise, Gnuplot;
# Uncomment following to true if you don't have the gnuplot
# executable installed on your platform:
#Gnuplot.options.dry = true;
# Uncomment the following and set the proper path if the
# gnuplot executable is not available in your $PATH
#Gnuplot.options.cmd = "/path/to/gnuplot";
# Set the default terminal for interacitve use
Gnuplot.options.term = "wxt size 700,400";
# Set the default linetypes
empty!(Gnuplot.options.init);
push!(Gnuplot.options.init, linetypes(:Set1_5, lw=1.5, ps=1.5));
# Initialize the gnuplot REPL using the provided `start_key`.
# Comment the following to disable the REPL.
Gnuplot.repl_init(start_key='>');
)
endAt the Julia prompt you may load the package and the associated settings by typing:
julia> @gnuplotrcand you're ready to go.