Is there a blind terminal in gnuplot to use for gathering x/y min/max without a screen plot - gnuplot

Using a flow where I do a 'scratch' plot first to then gather the 'GPVAL_DATA_Y_MIN / MAX' variables for framing the plot size. I then send the actual plot into PNG file. Still the 'scratch' plot command flashes up on screen which I want to avoid. I was doing a 'help set terminal' to see the available terminals (in my gnuplot session) and was looking for something like 'blind' or 'null' but couldn't find any like that. Is there such a terminal? And what is it's name? (Using gnuplot 4.6 patchlevel 7)
Thanks,
Gert

Since I don't know exactly, how you actually use those values, here are some different possibilities:
Gnuplot's "blind" terminal is called unknown:
set terminal unknown
plot "data.dat"
set terminal pngcairo
set output "output.png"
set yrange[GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX]
replot
Variants of this would be to wrap the set terminal unknown call in set terminal push and set terminal pop to go back to the previous terminal.
Use the stats command:
f = "data.dat"
stats f using 2 nooutput
set yrange [STATS_min:STATS_max]
plot f
If you don't need the values for computations, but only to fit the yrange to your actual data range, then use
set autoscale yfix
or
set autoscale yfixmax
possibly combined with set offsets.

Try to send the output to the null device:
On Linux:
set terminal png
set output "/dev/null"
plot sin(x)
set output "real_output.png"
...
On Windows:
terminal png
set output "nul"
plot sin(x)
set output "real_output.png"
...
Read this SO question or this Wikipedia entry, especially for Windows details.

Related

How to use `set term push` and `set term pop` in gnuplot

I am using gnuplot 5.2.7 on Arch Linux. I want to temporarily change the terminal's configuration, plot something, and then restore it (I have no terminal configuration in my initialization file). I think pop and push can be used to this effect, but I'm having no success.
This is what I do in a gnuplot session. First I set the terminal to wxt and push it, then plot a sine wave:
gnuplot> set term wxt 1 ; set term push
Terminal type is now 'wxt'
Options are '1 enhanced'
pushed terminal wxt 1 enhanced
gnuplot> plot sin(x)
So far this works. Now I want to temporarily change the background to cyan, and then revert to default background:
gnuplot> set term wxt 1 background "cyan"
Terminal type is now 'wxt'
Options are '1 background '#00ffff' enhanced'
gnuplot> plot sin(x)
gnuplot> set term pop
restored terminal is wxt 1 background '#00ffff' enhanced
gnuplot>
As you can see, poping the terminal didn't restore the background. The next plot comes up with a cyan background.
Gnuplot's manual (pdf) states, in page 257, that:
The command set term push remembers the current terminal including its
settings while set term pop restores it.
What am I doing wrong?
From the gnuplot manual:
The command set term push remembers the current terminal including its
settings while set term pop restores it. This is equivalent to save
term and load term, but without accessing the filesystem. Therefore
they can be used to achieve platform independent restoring of the
terminal after printing, for instance. After gnuplot's startup, the
default terminal or that from startup file is pushed automatically.
Therefore portable scripts can rely that set term pop restores the
default terminal on a given platform unless another terminal has been
pushed explicitly.
Actually, it's not completely clear to me what is the benefit of terminal push and terminal pop? Well, restoring the default terminal. The only advantage I can (currently) think of is that in a long gnuplot script when you are switching back and forth to different terminals you don't have to type in all the parameters of your default terminal again and again. And in case you change some terminal settings you otherwise would have to change all the occurrences in your script.
Maybe the following is useful to you: at the beginning of the code define your terminals with your backgrounds or other settings as string variables and then later call them as macro with #. So with this, I don't see a difference between calling #TerminalDefault and set terminal pop, except that #TerminalDefault will also restore if you had the same terminal before but just with different settings.
Code:
### workaround for terminal push & pop with same terminal but different settings
reset session
TerminalDefault = 'set term wxt 0 background "white"'
TerminalCyan = 'set term wxt 0 background "cyan"'
TerminalYellow = 'set term wxt 0 background "yellow"'
TerminalPNG = 'set term png background "green"'
#TerminalDefault
plot x
pause -1 TerminalDefault
#TerminalCyan
plot x**2
pause -1 TerminalCyan
#TerminalPNG
set output "Test.png"
plot x**3
set output
pause -1 TerminalPNG
#TerminalDefault
plot x**4
pause -1 TerminalDefault
### end of code

gnuplot : anomalous behaviour of 'set xrange' in an animated 2D-plot of MD data

I am working on a Windows 7 machine using gnuplot 5 Patch level 1.
I am preparing an animation of the sequence of interatomic distances along a trajectory from a molecular dynamics calculation.
The following script works fine:
set termopt enhanced # turn on enhanced text mode
# --- GRAPH a
set yrange [0.0:25.0]
set xlabel 't (fs)'
set ylabel "R_{ij} (A)"
set key box opaque
stats 'NeH2+_125K_TRAY171.DAT'
do for [i=1:STATS_records:2001] {
plot 'NeH2+_125K_TRAY171.DAT' using ($1/10):2 every ::1::i with lines title 'R_{NeH_{1}}', \
'NeH2+_125K_TRAY171.DAT' using ($1/10):3 every ::1::i with lines title 'R_{H_{1}H_{2}}',\
'NeH2+_125K_TRAY171.DAT' using ($1/10):4 every ::1::i with lines title 'R_{NeH_{2}}',
}
end of script
However the x-range is updated during the simulation and can be quite distracting since the data file is quite long.
To avoid updating the x-axis, I tried using the set xrange command
set xrange[0.0:7.0]
set yrange [0.0:25.0]
set xlabel 't (fs)'
...
When the animation starts, it works correctly but after plotting a few thousand data, it stops. Furthermore, there are no error messages in the console window of the aplication.
I have tested both scripts on a second windows 7 computer with gnuplot 5.2 and did observe the same behaviours.
Apparently the scripts are correct. Can anybody identify the problem?.
Thanks in advance.
Note, that the set yrange also applies to the stats call (yes, the yrange, because you don't specify any column).
So in any case you might have less plot iterations than you expect. Try
reset
f = 'NeH2+_125K_TRAY171.DAT'
stats f
set xrange [0.0:7.0]
set yrange [0.0:25.0]
do for [i=1:STATS_records:2001] {
plot f using ($1/10):2 every ::1::i title 'R_{NeH_{1}}', \
'' using ($1/10):3 every ::1::i title 'R_{H_{1}H_{2}}',\
'' using ($1/10):4 every ::1::i title 'R_{NeH_{2}}'
}

Gnuplot epslatex text missing [duplicate]

I am using the following script to generate a simple eps image:
set terminal epslatex 8
set output 'sample1.tex'
set size 0.75,0.75
set xrange [-pi:pi]
set yrange [0:1.2]
set xlabel "$x$"
set ylabel "$y$"
plot sin(x)*sin(x) title "$\\sin^2(x)$"
However, when I run it in gnuplot
gnuplot> load "sample.gpi"
I got a blank image, just the grids without numbers are shown.
Any suggestion what I'm doing wrong?
You are probably viewing the sample1-inc.eps file. But you must compile the output LaTeX-file first. For this it is very convenient to use the standalone option and compile from within the script itself:
set terminal epslatex 8 standalone
set output 'sample1.tex'
set size 0.75,0.75
set xrange [-pi:pi]
set yrange [0:1.2]
set xlabel "$x$"
set ylabel "$y$"
plot sin(x)*sin(x) title "$\\sin^2(x)$"
set output # finish the current output file
system('latex sample1.tex && dvips sample1.dvi && ps2pdf sample1.ps')
Now you can load 'sample1.gpi' and view the complete output as sample1.ps or sample1.pdf. If you are on Windows you may need to compile with three separate system calls (just guessing):
system('latex sample1.tex')
system('dvips sample1.dvi')
system('ps2pdf sample1.ps')

Show graph on display and save it to file simultaneously in gnuplot

How can I save graph in to file and also print it to display? I've tried:
#!/usr/bin/gnuplot -p
date=system("date +%F_%T | sed 's/:/-/g'")
set term png
set output date.".png"
set term x11
set out
plot sin(x)
PS: Is there a possibility to save the graph which is displayed in gnuplot window? I've noticed that there is copy to clipboard button but no save.
If you want to send a plot both to a file and to an interactive terminal like x11 or wxt you have the replot after you changed the terminal
set terminal png
set output 'file.png'
plot sin(x)
set terminal x11
set output
replot
If you don't want to set the x11 terminal explicitely, but rather use the default terminal, whatever it is, you can use the special terminals push and pop so save and restore a terminal:
set terminal push
set terminal pngcairo
set output 'file.png'
plot sin(x)
set terminal pop
set output
replot
To make this more transparent and save any image after you plotted it to an interactive terminal you could define a gnuplot script export.gp which you can then call and give the output file name as parameter.
The export.gp script is
set terminal push
set terminal pngcairo
set output '$0'
replot
set output
set terminal pop
which you can then use as
plot sin(x)
call 'export.gp' 'test.png'
Note, however, that the exported file and the plot shown in the interactive window will be different, but if you use wxt as interactive and pngcairo or pdfcairo as output terminals, the chances are quite high, that displayed and exported images are very similar.
With gnuplot 5.0 the qt and wxt terminals offer an "Export" button to save exactly the image shown in the window as svg, pdf or png files. Unfortunately, this functionality cannot yet be invoked from a script, i.e. there is no export command.
A good answer was also given in gnuplot - How can I save a graphics file of a plot that is the same as I designed it in xterminal?.
For x11 terminal one can use
system("xwd -id ".GPVAL_TERM_WINDOWID." | convert xwd:- screenshot.png")
It can be also wrapped into a short cut
bind "Ctrl-c" 'system("xwd -id ".GPVAL_TERM_WINDOWID." | convert xwd:- png:- | xclip -sel clip -t image/png")'
So you plot the image
set term x11
plot sin(x)/x
and then press Ctrl+c in the plot window. Just here, I pasted the image with Ctrl+v:
Unfortunately, it does not work for qt or wxt (GPVAL_TERM_WINDOWID is associated to x11). They have clipboard buttons, but snapshots are not scriptable.
Just expanding on Chistofs comprehensive answer
I like to keep the save commands and decide the file name at the end.
So, modifying the answer gave me this
plot sin(x)
set terminal push
set terminal pngcairo
set output 'test.png'
replot
set output
set terminal pop

Two interactive windows in Gnuplot with wxt terminal

I often use the wxt terminal of Gnuplot to do some quick data inspection. I like the interactivity, such that I can easily gain control and zoom/move et cetera.
Suppose I have to following script
set terminal wxt 0 persist
plot x
set terminal wxt 1 persist
plot x**2
Now, on window 1 I have the interactive control. However, on window 0 this interactive control is lost.
My question is: How can I obtain interactive control on window 0?
I am using gnuplot 4.6.2. I've seen gnuplot multiple graphs are not interactive but the question in about x11 terminal, and the answers consist of opening multiple instance of gnuplot, which seems unnecessary to me.
I believe have found a workaround for this problem.
But not sure if this works for all cases.
My solution sounds like obvious.
I created three files: configs.plt, wxt1.plt, and wxt2.plt.
The configs.plt file contains:
set style line 1 lc "#e41a1c"
set style line 2 lc "#377eb8"
The wxt1.plt file contains:
set terminal wxt title "plot sin"
load "configs.plt"
plot sin(x) w l ls 1
The wxt2.plt file contains:
set terminal wxt title "plot cos"
load "configs.plt"
plot cos(x) w l ls 2
The only boring thing is run two instead one file.

Resources