Total reset of a gnuplot session - gnuplot

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

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".

Related

Spurious '-' text with epslatex and multiplot

The following gnuplot snippet generates a multiplot showing six plots of data ported via stdin, but the special filename '-' used is also printed on the output:
set term epslatex color
set output 'mwe.tex'
set multiplot layout 3,2 scale 1,1 columnsfirst
set xrange [-3.1415:3.1415]
set yrange[-1.0:1.0]
set cbrange [-1:1]
set size ratio -1.0
set palette rgb 33,13,10
unset colorbox
plot '-' with image
-3.1416 -1.00 0.00
-3.1089 -1.00 0.00
(...)
e
(...)
unset multiplot
(The 'plot' command and what follows until and including 'e' is repeated six times with different input before the unset multiplot command.)
The output is shown here. The special filename '-' must be included in the plot command to plot inline data, but it should not be shown in the resulting plot. How to avoid this behavior?
The problem persists when using the 'standalone' term option with epslatex, but it does not show up when using other terminals.
I use gnuplot 4.6 patch 2.
According to the StackOverflow rule "no answer in the comments", here again as answer. Also check help key and the options there.
Try:
set key noautotitle
or
plot '-' with image notitle

gnuplot: why is linewidth 0 not zero in width?

What is the reason that lw 0 doesn't have zero linewidth, i.e. invisible?
What I find in the gnuplot manual:
The line width and point size are multipliers for the current
terminal's default width ...
Ok, if lw 0 is a multiplier then the resulting linewidth should be zero independent of the terminal's default linewidth.
The reason for asking is to eventually have the possibility to use with linespoints and programmatically switch within a loop between with lines and with points.
Code:
### linewidth 0 isn't zero
reset session
set key out
set yrange[-0.9:10.9]
set ytics 1
plot for [i=0:10] i with lines lw i title sprintf("linewidth %g",i)
### end of code
Result:
By the way, what are the artefacts at the y-axis e.g. at ytics 3,4,6,7,9,10 (wxt-terminal)?
Mike Nakis is correct that for at least some of the gnuplot output terminals, including PostScript, gnuplot asks for a 0 width line and the language or library in question interprets that as "1 pixel" or "thinnest possible line".
Similarly "pointtype 0" is not truly missing, it produces a single pixel dot.
You can, however, disable the line drawing altogether by using linetype "nodraw".
That gives a complementary pair of commands
plot sin(x) with linespoints lt nodraw pt 7 # only the points are visible
plot sin(x) with linespoints lt 1 pt 0 # only the lines are visible
In some circumstances it may help to know that the numeric equivalent for lt nodraw is lt -2.
I don't know for sure what the official explanation is for gnuplot in particular, but in my experience, most graphics packages / tools / libraries etc. use a special convention for a line width of zero.
According to this convention, a line width of zero does not mean invisible; it simply means "the thinnest line possible". This means the thinnest line that can be displayed on the device, regardless of zoom, transformations, logical-to-physical mapping, etc.
So, on monitors, it will be a line which is one pixel wide.
On a printer, it will be the thinnest line that the printer is capable of producing. So, if the printer has a high enough resolution, then the line might practically be invisible, though a magnifying glass should still be able to reveal its existence.
And note that "regardless of zoom, etc." means that even if you set up some scaling that makes your 10-point line look as thick as 100 pixels, the zero-width line will still be exactly one pixel thick.

short dashed line length in gnuplot

I have a horizontal line in a diagram with the following terminal set in gnuplot:
set terminal postscript eps size 8.5cm, 7cm enhanced color font 'Helvetica,10'
set style line 5 lt 2 lc rgb "black" lw 3
f(x)=5.0
plot f(x) w l ls 5
The line width is ok, but the length of the dashes are too short. How can I increase it without changing the terminal mode to dashed line?
For the postscript terminal the default mode is already dashed, which you see when you type your set terminal line in the interactive gnuplot-terminal:
gnuplot> set terminal postscript eps size 8.5cm, 7cm enhanced color font 'Helvetica,10'
Terminal type set to 'postscript'
Options are 'eps enhanced defaultplex \
leveldefault color colortext \
dashed dashlength 1.0 linewidth 1.0 butt noclip \
nobackground \
palfuncparam 2000,0.003 \
size 8.50cm, 7.00cm "Helvetica" 10 fontscale 1.0 '
Otherwise, in solid mode, the only dashed linetype is lt -1.
The above message also tells you, how you can change the dashlength. Up to version 4.6, the only way to change the dashlength is to use the dashlength option, e.g. with
set termoption dashlength 1.5
Unfortunately, this affects all line types.
Only 5.0 version supports arbitrary, configurable dash patterns. Note also, that in version 5 the dashlength depends on the selected line width.
I have used this and the results are not bad for me, (gnuplot 4.2):
set terminal postscript eps enhanced color dl 2.0 font 'TimesRoman' 24
Here, by changing dl 2.0 to dl 3.0, you can get larger dash lines.

Dash line in windows terminal -gnuplot

I am using gnuplot for Windows using the default windows terminal. I need to plot a dashed line instead of normal solid line
I used
set style line 1 lt 0 lc 3
plot 'dashcca.txt'
but it does not work
Any suggestions?
See help terminal windows, which shows you the terminal option dashed. Either use
set terminal windows dashed
or
set termoption dashed
And of course you must use a line type which is dashed. Type test to see all supported line types with the current terminal settings.
In order to use a certain dash pattern with a different line color, use e.g.
plot x linetype 2 linecolor 1
This uses the dash pattern of line type 2, and the color of line type 1 (red). You can use arbitrary colors with linecolor rgb:
plot x linetype 2 linecolor rgb 'black', x**2 linetype 3 linecolor rgb '#bb0000'

Gnuplot - Using replot with png terminal

I am trying to use replot with png terminal in Gnuplot.
If I do the following I get two plots on one graph without any problem:
plot sin(x)/x
replot sin(x)
Now if do the same for a png terminal type the resulting png file only contains the first plot.
set terminal png
set output 'file.png'
plot sin(x)/x
replot sin(x)
Am I missing something at the end to get the second plot in my png file?
This is actually a very good question, and the behavior here is terminal dependent. Some terminals (e.g. postscript) will give you a new page for each replot. You have a couple of solutions...
First Option: You can make your plot prior to setting the terminal/output and then replot again after you set the terminal/output:
plot sin(x)/x
replot sin(x)
set terminal png
set output 'file.png
replot
This option is sometimes convenient if you want to plot the same thing in multiple terminals, but I rarely use it for anything else.
Second (better) Option: You can pack multiple plots into one command separating each with a comma.
set terminal png
set output 'file.png'
plot sin(x)/x, sin(x)
I very much prefer the second way -- when in a multiplot environment, this is the only way to put multiple graphs on the same plot. If you have very long functions to plot, you can break the line with gnuplot's line continuation (\ at the end of the line -- Nothing is allowed after the \, not even whitespace)
plot sin(x)/x with lines linecolor rgb "blue" linetype 7 lineweight 4, \
sin(x), \
cos(x)

Resources