I'm plotting a gnuplot diagram with float values in the y-axis and time values in the x-axis.
The plotting itself works like a charm, but I can't get newlines in the time format to work.
If I use the format specifier "%d.%m.%y %H:%M" it works like a charm, and the result is: 25.05.1983 17:23. But when I add a newline character, so I have "%d.%m.%y\n%H:%M" the resulting labels are actually containing a line break but all I see is: 25.05.1983.
I also tried to increase the bmargin by several values, up to the point where the resulting plot was squished, but I just can't get the time to be shown.
Is the newline character not supported in a time format? Or does this not work at all with labels? Or maybe the png enhanced terminal doesn't support it?
UPDATE
Sample input data
20140617000045
20140617000245
20140617000445
20140617000645
I don't have any space between date and time.
With your test data the following script works fine with 4.6.5:
set terminal pngcairo enhanced
set output 'timetest.png'
set xdata time
set timefmt '%Y%m%d%H%M%S'
set format x "%d.%m.%y\n%H:%M"
plot 'test.dat' using 1:0 with lp notitle
The output is:
Yes, the png terminal works fine as well (but its output is in general uglier).
Related
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}}'
}
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.
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.
Suppose I'm plotting some geographic data in gnuplot, and I'd like to set tic-mark labels in the DMS (deg°min′sec″) format; e.g.
37°31′40″N
37°31′20″N
37°31′00″N
37°30′40″N
37°30′20″N
37°30′00″N
without creating lots of custom labels manually. Is this possible? How can I do this?
It depends a lot of the terminal you're using. On a mac with aqua terminal, this works:
set timefmt "%Y°%M′%S″N"
set format x "%y˚%M\'%S\"N"
set xdata time
plot 'test.dat' u 1:0
Using gnuplot 4.6 patchlevel 1, with the following commands,
set grid linewidth 1 linecolor rgb"#888888"
set datafile separator ","
plot for [n=2:100] "data.csv" using 1:(column(n)) with lines linewidth 2
and the following example data in the file "data.csv",
time,S1,S2
0,0.00015,0
0.1,0.0001357256127053939,1.427438729460607e-005
0.2,0.0001228096129616973,2.719038703830272e-005
0.3,0.0001111227331022577,3.887726689774233e-005
0.4,0.0001005480069053459,4.945199309465411e-005
0.5,9.097959895689501e-005,5.902040104310499e-005
0.6,8.232174541410396e-005,6.767825458589604e-005
0.7,7.448779556871142e-005,7.551220443128858e-005
0.8,6.739934461758323e-005,8.260065538241677e-005
0.9,6.098544896108986e-005,8.901455103891014e-005
1,5.518191617571635e-005,9.481808382428365e-005
the resulting plot looks this:
Question: why does the grid only extend partway from the bottom, and not cover the whole plot? I tried a considerable amount of experimentation with the set xtics and ytics commands, arguments to grid, and more, and have not been able to get the grid to cover the whole plot. What am I missing?
Great question! In fact, the answer is that the grid does cover the whole plot. The problem is that the key is taking over. Try it again, but with an unset key in there before your plot command.
What's happening is that gnuplot is reserving space in the key for all of the columns which have no data. Nothing gets put in the space that was reserved since no reasonable data was found. Ultimately, this pushes the 2 lines that were visible out of the viewable canvas area as well.
I've reproduced this using the x11, png, postscript and pngcairo terminals.
Note that this behavior seems to be version dependent:
With gnuplot 4.4.2 (OS-X, png terminal)
With gnuplot 4.6.0 (OS-X, png terminal)
For those using gnuplot 4.4.4, perhaps there was a bug fix which made it work for gnuplot 4.4.4 and then a regression. It seems to persist into gnuplot 4.7.0 as well. I might file a bug report.