Display options

The display behaviour of Gnuplot.jl depends on the value of the Gnuplot.options.gpviewer flag:

  • if true the plot is displayed in a gnuplot window, using one of the interactive terminals such as wxt, qt or aqua. This is the default setting when running a Julia REPL session; The terminal options can be customized using Gnuplot.options.term;

  • if false the plot is displayed through the Julia multimedia interface, i.e. it is exported as either a png, svg or html file, and displayed in an external viewer. This is the default setting when running a Jupyter, JupyterLab or Juno session. The terminal options can be customized using the Gnuplot.options.mime dictionary.

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 is false, but if the package is not able to start a gnuplot process it will automatically switch to true;

  • 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 (if true) or an external viewer (if false);

  • 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 either save() or show() (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. If true all communication with the underlying process will be printed on stdout. E.g.:


julia> Gnuplot.options.verbose = true;

julia> x = 1.:10;

julia> @gp x x.^2 "w l t 'Parabola'"
GNUPLOT (default) 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) 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) unset multiplot
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 enhanced

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

Package 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. A possibility is 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";

        # Force a specific display behaviour (see documentation).  If
        # not given explicit Gnuplot.jl will choose the best option
        # according to your runtime environment.
        #Gnuplot.options.gpviewer = true

        # 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 with `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;
    )
end

At the Julia prompt you may load the package and the associated settings by typing:

julia> @gnuplotrc

and you're ready to go.