Search code examples
gnuplot

Total reset of a gnuplot session


I would like a way to completely reset a gnuplot session from within gnuplot; exactly equivalent to exiting and restarting.

The commands reset or reset session (http://www.bersch.net/gnuplot-doc/reset.html) are not sufficient, since some options that were set before linger after either command (e.g., set term, set output, ...).

Note that the solution to how to completely reset gnuplot? is not sufficient for my purposes.

For context, the problem I am having is that I often use the same terminal session to execute many different gnuplot scripts to make many different plots. For some of those plots I want to simply use default options, while for others I prefer to be more specific. If I run one of the more "specific" scripts before I run one of the "default" scripts many of the "specific" settings are applied to the "default" plot, even when each script begins with a reset session command. My current solution is to manually restart gnuplot, which is a bit annoying.

The following minimal script illustrates an example of the problem: After running both the reset and reset session commands the terminal is not reset to whatever the default is. Here by 'default' I mean whatever terminal loads up when it starts, in my case qt. Note that the terminal type is just one example of a number of things that linger after the reset commands. I want some way of restoring gnuplot to exactly the state it starts in.

show terminal

set terminal pdfcairo

show terminal

reset
reset session

show terminal

Solution

  • I don't think the hard reset you mention is provided by gnuplot. As your example shows, it seems to be difficult to do an exact reset with the reset session.

    As a workaround, you might try the following method using an initialization script. help reset says,

    The following are not affected by reset: set term set output set loadpath set linetype set fit set encoding set decimalsign set locale set psdir set overflow set multiplot

    And, help reset session mentions also like this,

    reset session deletes any user-defined variables and functions, restores default settings, and then re-executes the system-wide gnuplotrc initialization file and any private $HOME/.gnuplot or $XDG_CONFIG_HOME/gnuplot/gnuplotrc preferences file. See initialization.

    According to this behavior, I recommend that you write the default settings you need in the initialization file "$HOME/.gnuplot" that will be called when you do reset session.

    Here are the steps to do so:

    (1) Invoke gnuplot with the -d option.

    (2) Run command save "settings.plt" to save the current settings to "settings.plt".

    (3) Extract the necessary settings from the contents of "settings.plt".

    Here is the case in my environment (it may be different in yours).

    set terminal x11  nopersist enhanced
    set output
    set loadpath 
    set fit brief errorvariables nocovariancevariables errorscaling prescale nowrap v5
    set encoding default
    unset decimalsign
    set locale "C"
    set psdir
    

    The save command does not write out the configuration of the linetype, it needs to be examined separately.

    (4) Run command show linetype to find out the default settings of the linetype.

        linetype 1,  linecolor rgb "red"  linewidth 1.000 dashtype solid pointtype 1 pointsize default
        linetype 2,  linecolor rgb "#009e73"  linewidth 1.000 dashtype solid pointtype 2 pointsize default
        linetype 3,  linecolor rgb "#56b4e9"  linewidth 1.000 dashtype solid pointtype 3 pointsize default
        linetype 4,  linecolor rgb "#e69f00"  linewidth 1.000 dashtype solid pointtype 4 pointsize default
        linetype 5,  linecolor rgb "#f0e442"  linewidth 1.000 dashtype solid pointtype 5 pointsize default
        linetype 6,  linecolor rgb "#0072b2"  linewidth 1.000 dashtype solid pointtype 6 pointsize default
        linetype 7,  linecolor rgb "#e51e10"  linewidth 1.000 dashtype solid pointtype 7 pointsize default
        linetype 8,  linecolor rgb "black"  linewidth 1.000 dashtype solid pointtype 8 pointsize default
        Linetypes repeat every 8 unless explicitly defined
    

    See help linetype for more information on how to write it.

    (5) Write them in "$HOME/.gnuplot".