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

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}}'
}

Related

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

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.

gnuplot graph with time fmt not working

I have created a script that logs various system resources, and will graph all data points into gnuplot with a nice smooth line. I am running into issues with gnuplot using my time format and plotting the data correctly. A sample of my data file is below
My time format = %H%M%S
"etc. etc." = hundreds of additional recorded times.
170554 3.0%
170556 2.7%
170558 2.6%
etc.
etc.
010218 2.1%
010218 2.3%
If the time of all data plots does not go over the 000000 mark, gnuplot graphs everything correctly. Once my data plots go over that 000000 boundary, gnuplot counts backwards in my time format, so it tries to plot everything that has not been recorded from 170554 - 010218 (numbers not recorded).
Example. 170552 160424 150720 120818.
My gnuplot command I am using is below.
gnuplot -persist -e "set title 'Resource Monitor'; set timefmt '%H%M%S'; set xdata time; set xlabel 'TIME'; set ylabel 'PERCENT'; set yrange [0:101]' set xrange ['170554':'010218']" -e "plot 'log_file' using 1:2 title 'CPU' smooth Bezier"
So my question is...
Why is gnuplot not plotting my graph correctly (the way I want it to via time) and how can I fix this issue? Thank you.
From the documentation
If <ub> is lower than <lb> the constraints will be turned off and full
autoscaling will happen.
To fix it, you will need to supplement your time data with additional "day" information, or find some other way to ensure that later times are never "lower than" earlier times.

Setting gnuplot yrange to fit one curve only

I have a Gnuplot script that draws 2 curves from a data file. If I don't specify yrange, Gnuplot sets it so that all the points of both curves fit in the figure. In my case I would like Gnuplot to only care about one of the curve (it does not matter if the other goes out of range, since I'm interested only in the parts of the figure where the second curve gets close to the first one).
I could find out the minimum and maximum values taken by the first curve, and manually set yrange to those values, but my Gnuplot script is intended to run automatically on many data files, producing many figures for which yrange is not the same, so I'm looking for a way to do that automatically.
Thanks
There are different options, depending on the used gnuplot version:
Version 5.0:
The data file which should be excluded from the autoscaling gets a noautoscale parameter:
plot 'first.dat' using 1:2, 'second.dat' using 1:2 noautoscale
Version >= 4.6:
Use the stats command to get the minimum and maximum value of the relavant data file:
stats 'first.dat' using 1:2
set yrange [STATS_min_y:STATS_max_y]
plot 'first.dat' using 1:2, 'second.dat' using 1:2
At least since 4.0:
Use set yrange [] writeback to save the autoscaled ranges from a plot command and set yrange restore to use them for a later plot:
set terminal push
set terminal unknown
set yrange [] writeback
plot 'first.dat' using 1:2
set yrange restore
set terminal pop
plot 'first.dat' using 1:2, 'second.dat' using 1:2

Gnuplot nested do loop and plotting on the same graph

Hi I'm using gnuplot to create a large number of graphs. To save myself work I've written a script that tries to plot all possible graphs.
#!/usr/bin/gnuplot
reset
is_missing(x)=system("./ismissing.sh ".x)
set terminal post eps enhanced color
set key inside right top vertical Right noreverse enhanced autotitles box linetype -1 linewidth 1.000
set grid
models="Cebeci-Smith Baldwin-Lomax Spalart-Allmaras Launder-Sharma Chien"
files="./CebeciOut/ ./BaldwinOut/ ./SpalartOut/ ./LaunderOut/ ./ChienOut/"
xgrid="35000 70000 140000 280000 560000"
# Plot grid convergence Spalart
do for [f=1:words(files)]{
set output sprintf('%s%s',word(files,f),'ZPGGridConvergence.eps')
set title sprintf("%s%s",word(models,f), " ZPG Grid Convergence")
set xlabel "N_y"
set ylabel "C_f Final"
print f
do for [i=1:words(xgrid)]{
filename=sprintf("%s%s%s%s",word(files,f),'yconv_',word(xgrid,i),"x")
if(is_missing(filename)==0){
plot filename using 1:2 title sprintf("%s%s",word(xgrid,i), " X Gridpoints") with linespoints
}
}
}
Unfortunately I have a problem, after one full iteration the script fails, ie f is never made 2 despite the first plots completing successfully. The error given is
cannot open file; output not changed
line 25: util.c: No such file or directory
which I haven't managed to decipher. Any help would be much appreciated. Also is there a way to use replot in this loop given I haven't already created a plot.
Thanks
"files" are actually dirs in your code.
If you want to place the output in a subdir, then make sure that it exists and is writable.
gnuplot cannot create subdirs automatically. You can add system("mkdir -p ".word(files,f)) ( on linux/unix) in your code to create the directory if needed.

gnuplot ignores x and y ranges when using dgrid3d

I have a file with scattered data (points located approximatelly on the vertices of a regular grid): first two columns are the x and y coordinates, then a few more columns with other data that I need to plot. I want to obtain color maps that represent this data, and since points are scattered I'm using dgrid3d to generate a regular grid and have a smoother representation. My problem is that when I set dgrid3d, gnuplot ignores the x and y ranges and plot the grid outside the figure frame. Bellow is a minimal script to reproduce my problem:
set view map
set yrange [0.4:0.8]
set xrange [0.2:0.8]
set pm3d
set style data lines
set dgrid3d 100,100,4
splot "./Terr.dat" using 1:2:(log($6)) pal
The result that I obtain is the following image:
Setting the option clip1in or clip4in of pm3d has no effect. If I unset view so that the result is a 3D surface, it also ignores the x and y ranges. I could easily write an script to pre-process the data and remove the points outside the range I want, but gnuplot should be able to manage this. Any idea?
I'm using gnuplot 4.2 patchlevel 6
Thanks!
I'm not sure that I am able to reproduce your problem, but there are a few funny things with your script. I'm not exactly sure what the line set style data lines is supposed to do in this context as you're plotting with pm3d. I created a simple datafile:
0 1 4
1 0 5
0 0 2
1 1 3
And I plotted it using this script:
set view map
set yrange [0.4:0.8]
set xrange [0.2:0.8]
set dgrid3d 100,100,4
splot 'test.dat' u 1:2:3 w pm3d
And it seemed to "work" (I'm using gnuplot 4.6.0).
There are a few things of note however -- Notice that every point in my original domain was out of the given x and y ranges. Gnuplot still used those points when constructing the surface. This is also demonstrates reasonably nicely what the gnuplot weighting function looks like (although we could do even better by using only 1 point in our data file.)
UPDATE
Between my 2 computers, I have access to gnuplot4.2.6, gnuplot4.3.0, gnuplot4.4.2, gnuplot4.6.0, gnuplot4.6.1 and gnuplot4.7.0. gnuplot4.2.6 is the only version which exhibits the behavior you describe. It looks to me like they changed the behavior of pm3d in the 4.3 CVS branch, but didn't push those changes back into gnuplot4.2. The easy fix is to upgrade to gnuplot4.6 -- I've been using it as my default gnuplot for a few months now and it seems to be pretty stable.

Resources