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, VSCode or Juno session.

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";
  • 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 (three) set term wxt size 700,400 GNUPLOT (three) print GPVAL_TERM GNUPLOT (three) -> wxt GNUPLOT (three) print GPVAL_TERMOPTIONS GNUPLOT (three) -> 0 size 700, 400 enhanced GNUPLOT (three) set term wxt 0 size 700, 400 enhanced title 'Gnuplot.jl: three' GNUPLOT (three) $data2 << EOD GNUPLOT (three) 1.0 1.0 GNUPLOT (three) 2.0 4.0 GNUPLOT (three) 3.0 9.0 GNUPLOT (three) 4.0 16.0 GNUPLOT (three) ... GNUPLOT (three) EOD GNUPLOT (three) reset GNUPLOT (three) GNUPLOT (three) plot $data2 w l t 'Parabola' GNUPLOT (three) unset multiplot
julia> Gnuplot.save("output.png", term="pngcairo size 480,360 fontscale 0.8")GNUPLOT (three) print GPVAL_TERM GNUPLOT (three) -> wxt GNUPLOT (three) print GPVAL_TERMOPTIONS GNUPLOT (three) -> 0 title "Gnuplot.jl: three" size 700, 400 enhanced GNUPLOT (three) reset GNUPLOT (three) unset multiplot GNUPLOT (three) set term pngcairo size 480,360 fontscale 0.8 GNUPLOT (three) set output 'output.png' GNUPLOT (three) GNUPLOT (three) plot $data2 w l t 'Parabola' GNUPLOT (three) unset multiplot GNUPLOT (three) set output GNUPLOT (three) set term wxt 0 title "Gnuplot.jl: three" size 700, 400 enhanced "output.png"

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 for verbose is false;

Package initialization

If you use Gnuplot.jl frequently you may find convenient to automatically apply the package settings (Options) whenever the package is loaded. A possibility is to use the atreplinit function and within the startup.jl initialization file (further info here), e.g.:

atreplinit() do repl
    try
        @eval begin
            using Gnuplot

            # Uncomment the following if you don't have gnuplot
            # installed on your platform:
            #Gnuplot.options.dry = true

            # 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 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
            # (only meaningful if Gnuplot.options.gpviewer = true)
            if Gnuplot.options.gpviewer
                Gnuplot.options.term = "wxt size 700,400 lw 1.4 enhanced"
            end

            # Set the default linetypes
            empty!(Gnuplot.options.init)
            push!(Gnuplot.options.init, Gnuplot.linetypes(:Set1_5, lw=1.5, ps=1.5))

            # Initialize the gnuplot REPL
            if Gnuplot.options.gpviewer
                Gnuplot.repl_init(start_key='>')
            end
        end
    catch err
        @show err
    end
end