How can I set tic-mark labels in the DMS (deg° min′ sec″) format? - gnuplot

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

Related

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

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: How to set new line in xtics timefmt

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

Resources