Display options
The display behaviour of Gnuplot.jl depends on the value of the Gnuplot.options.gpviewer boolean option:
if
truethe plot is displayed in a gnuplot window, using one of the interactive terminals such aswxt,qtoraqua. There is exactly one window for each session, and the plots are updated by replacing the displayed image. The preferred terminal can optionally be set usingGnuplot.options.term;if
falsethe plot is displayed through the Julia multimedia interface, i.e. it is exported as either apng,svgorhtmlfile, and displayed in an external viewer. In this case the package is unable to replace a previous plot, hence each update results in a separate image being displayed. The terminal options to export the images are set inGnuplot.options.mime.
The latter approach can only be used when running a Jupyter, JupyterLab or Juno session, while the former approach is appropriate in all cases (most notably, for the standard Julia REPL). The Gnuplot.options.gpviewer flag is automatically set when the package is first loaded according to the runtime environment, however the user can change its value at any time to fit specific needs.
Further informations and examples for both options are available in this Jupyter notebook.
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;gpviewer::Bool: use a gnuplot terminal as main plotting device (iftrue) or an external viewer (iffalse);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";mime::Dict{MIME, String}: dictionary of MIME types and corresponding gnuplot terminals. Used to export images with eithersave()orshow()(see Display options). Default values are:MIME"application/pdf" => "pdfcairo enhanced"MIME"image/jpeg" => "jpeg enhanced"MIME"image/png" => "pngcairo enhanced"MIME"image/svg+xml" => "svg enhanced mouse standalone dynamic background rgb 'white'"MIME"text/html" => "svg enhanced mouse standalone dynamic"MIME"text/plain" => "dumb enhanced ansi"
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'
GNUPLOT (default) unset multiplot
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) unset multiplot
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";
ERROR: type Options has no field term_png
julia> Gnuplot.options.term_svg = "svg dynamic";
ERROR: type Options has no field term_svgPackage initialization
If you use Gnuplot.jl frequently you may find convenient to collect all the package settings (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 Gnuplot;
# Uncomment the following if you don't have the gnuplot
# executable installed on your platform:
#Gnuplot.options.dry = true;
# Set the proper path if the gnuplot executable is not
# available in your $PATH
#Gnuplot.options.cmd = "/path/to/gnuplot";
# Set the display behaviour (see documentation, or let Gnuplot.jl
# choose the best option according to your runtime environment):
#Gnuplot.options.gpviewer = true/false
# Set the default terminal for interacitve use
Gnuplot.options.term = "wxt size 700,400";
# Set the terminal options for the exported MIME types:
#Gnuplot.options.mime[MIME"image/png"] = "";
#Gnuplot.options.mime[MIME"image/svg+xml"] = "svg enhanced standalone dynamic";
#Gnuplot.options.mime[MIME"text/html"] = "svg enhanced standalone mouse dynamic";
# Set the terminal to plot in a terminal emulator:
# (try `save(MIME"text/plain")`):
#Gnuplot.options.mime[MIME"text/plain"] = "sixelgd enhanced"; # requires vt340 emulation
# 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`.
if Gnuplot.options.gpviewer;
Gnuplot.repl_init(start_key='>');
end;
)
endAt the Julia prompt you may load the package and the associated settings by typing:
julia> @gnuplotrcand you're ready to go.