Gnuplot no variable "pause" - gnuplot

With the following gnuplot script
set logscale y
set title "Residuals"
set ylabel 'Residual'
set xlabel 'Iteration'
plot "< cat log | grep 'solving for p' | cut -d ' ' -f9 | tr -d ','" title 'p' with lines,\
pause 1
and this version
$ gnuplot --version
gnuplot 4.6 patchlevel 2
I get the following error:
"residuals", line 6: undefined variable: pause
How can I fix that?

Your plot command is incorrect because the line ends with ",\" which means your line is continuing and pause is being treated as a variable passed to plot. So pause doesn't exist.
I suggest removing ",\".

Related

How to run a shell command in Gnuplot and place the output in new file

I have the following Gnuplot:
set encoding iso_8859_1
set key right bottom #font "Helvetica,17"
set ylabel "Lookup error probability" font "Helvetica,17"
set xlabel "Hight of the reader (m)" font "Helvetica,17"
set xtics font "Helvetica,15"
set ytics font "Helvetica,15"
set size 0.75, 1.05
set terminal postscript eps enhanced color #"Helvetica" 16 #size 3.5in,3in
set grid
set key spacing 1.5
set output "ProbError6x6.eps"
list(start,end,increment)=system(sprintf("seq %g %g %g", start, increment, end))
system("(awk '(NR>8 ){print; }' Hight_6x6.csv | sed -e 's/[",]/ /g' | sort -nk36) > pe_H_6x6.txt")
set print "pe_H_6x6.dat"
do for [i in list(2,3.5,0.25) ] {
stats "pe_H_6x6.txt" u ($36==i?($37/$38):1/0) name "A" nooutput
print i*1, A_mean, (A_mean - 1.833*A_ssd/sqrt(A_records)),\
(A_mean + 1.833*A_ssd/sqrt(A_records))
}
plot [][] "pe_H_6x6.dat" using 1:2:3:4 with yerrorlines ls 2 title "6x6 blocks"
The line with the system and with the awk code does not work in my Gnuplot script. However, it works in the unix shell. This code removes commas and , in Hight_6x6.csv, skips the first 8 lines and sort the result by the values of the 36th column.
I cannot make it work in the Gnuplot script.
The CSV file is in this link.
Your issue is probably that you include a double quote inside the command:
system("(awk '(NR>8 ){print; }' Hight_6x6.csv | sed -e 's/[",]/ /g' | sort -nk36) > pe_H_6x6.txt"
^
One work-around is to use backquotes, e.g.:
`(awk '(NR>8 ){print; }' Hight_6x6.csv | sed -e 's/[",]/ /g' | sort -nk36 > pe_H_6x6.txt`
Or as I would have written it:
`tail -n+8 Hight_6x6.csv | tr '",' ' ' | sort -nk36 > pe_H_6x6.txt`

"x range is invalid" when using values with $

I'm on linux, learning gnuplot. My data.tsv looks like this:
1480420804 2016-11-29 04:00:04 -0800 foo1 $123.00 bar1
1480507205 2016-11-30 04:00:05 -0800 foo2 $124.25 bar2
1480593604 2016-12-01 04:00:04 -0800 foo3 $122.75 bar3
I'm using column #1 (seconds since epoch) as X, and column 4 (price) as Y.
This is my gnuplot script:
#!/usr/bin/gnuplot
set terminal png notransparent interlace size 640,480
set output "output.png"
set datafile separator tab
set xdata time
set timefmt "%s"
set format x "%4Y-%02m-%02d"
plot "data.tsv" using 1:4 title "Blah"
When I try to run this, I get the following error:
"./test.gp", line 9: warning: Skipping data file with no valid points
plot "data.tsv" using 1:4 title "Blah"
^
"./test.gp", line 9: x range is invalid
But if I remove all the dollar signs from the start of column 4 in my data.tsv file, then everything works.
My question: Is there a way to get gnuplot to accept or skip over the "$" in the prices in column #4?
(This is not an answer to your question but an answer to your problem so be welcome to accept another answer if somebody comes up with something better)
Just preprocess you data file before plotting and remove the $:
sed s/\$//g data.tsv >data2.tsv
I tried to do (more-or-less) what #kebs suggested, but it failed with the same "x range is invalid" error message when I was calling it like this within gnuplot:
plot "< sed s/\$//g data.tsv" using 1:4 title "Blah"
I'm not too familiar with sed, so I tried instead to use tr, and that worked like a charm.
Line 9 of my gnuplot script was this:
plot "data.tsv" using 1:4 title "Blah"
I changed it to say this:
plot "< cat data.tsv | tr --delete '$'" using 1:4 title "Blah"

How to fix gnuplot -e "plot 'file' u 1:($2)-1 w l" syntax?

I need to plot files using gnuplot without going to gnuplot terminal. So, I am taking a quick look at the plots using the following line.
i=2; while [ $i -le 14 ] ; do gnuplot -e "plot 'pop05' u 1:$i w l, 'pop01' u 1:$i w l; pause 2"; ((i++)); done
However, gnuplot -e does not seem to work for the cases of
gnuplot -e "plot 'pop01' u 1:($2)-1 w l"
ie, when I try to use an altered value in a particular column like I subtract 1 from the second column. However, plot 'file' u 1:($2)-1 w l works perfectly in gnuplot terminal. What should be the syntax for me to plot an altered column in the loop as well as without the loop?
I use gnuplot 4.4 patchlevel 3.
$2 has a special meaning in shell in double quotes (it returns the second positional argument). Just backslash the dollar sign:
gnuplot -e "plot 'pop01' u 1:(\$2)-1 w l"

Howto improve a coloured line plot by key in third column?

I'm trying to plot temperatures of my laptop, here are my working files at github
I have epoch, temperature & kernel identifier data like so:
1357786501 72 3.6.11-1-ARCH
1357786801 72 3.6.11-1-ARCH
1357787101 60 3.0.57-1-lts
1357787401 54 3.0.57-1-lts
1357800301 52 3.0.57-1-lts
1357800601 48 3.6.11-1-ARCH
1357800902 45 3.6.11-1-ARCH
The closest I've got to what I want is (using this):
set term svg size 1024,708
set xdata time
set key outside
set timefmt "%s"
set ytics 5
set format x "%d/%m"
plot "< awk '{if($3 == \"3.0.57-1-lts\") print}' temp.csv" u 1:2 t column(3) w p pt 2, \
"< awk '{if($3 == \"3.6.10-1-ARCH\") print}' temp.csv" u 1:2 t column(3) w p pt 2, \
"< awk '{if($3 == \"3.6.11-1-ARCH\") print}' temp.csv" u 1:2 t column(3) w p pt 2, \
"< awk '{if($3 == \"3.8.1-1-mainline-dirty\") print}' temp.csv" u 1:2 t column(3) w p pt 2
gihub kaihendry
Is there a way to avoid using awk? When I don't use this awk, it fails to plot differing kernel identifiers.
Can I make it a continuous line with different colours instead somehow?
Any ideas how to make SVG output without width/height? Any tricks to make it look better?
If your version of Gnuplot is recent enough, you can use a for-loop and iterator to loop over the different strings you want to match, see for example manual page 88-89 or this blog entry. To ignore non-matching lines you can use the ternary operator (cond ? iftrue : iffalse) to set these values to "Not-A-Number" (1/0 or NaN):
set xdata time
set key outside
set timefmt '%s'
set ytics 5
set format x '%d/%m'
set style data linespoints
archs = "`cut -d' ' -f3 temp.csv | sort -u | tr '\n' ' '`"
plot for [arch in archs] 'temp.csv' using 1:((strcol(3) eq arch) ? $2:1/0) title arch

Can the string for "set title" be obtained from a file?

I'm using Gnuplot with scripts and data files.
In my script there is a command;
set title "blah title here"
Is it possible to have that string taken from a data file? e.g. such that I can use a single script with many data files, because the data file will contain the title for the plot.
I'm not sure if this would be easy to do in pure gnuplot, but here is a solution using a wrapper bash script. You would use the script by calling plotscript.sh data.dat at the command line.
#!/bin/bash
my_title=$(head -n 1 $1 | sed 's/^# \(.*\)/\1/')
echo "set terminal postscript enhanced color
set output 'plot.eps'
set title '$my_title'
plot '$1' u 1:2" | gnuplot
To make the script usable put the code in a textfile and run chmod +x on it. If you tell me what format the title is in I can try to tailor the script to match that. This script assumes that the title is the first line of the data file in this type of format:
# mytitle
1 4
2 5
3 2
you can use backtic substitution...e.g.
set title "`head -1 datafile.dat`"
However, that doesn't quite get what you want since the backtic substitution is done prior to string operations (You can't specify the datafile name as a string). However, Macros are expanded prior to backtic substitutions.
My test datafile looked like:
"this is the title"
10 20
20 30
30 40
And my test script looked like:
DATAFILE="datafile.dat"
set macro
TI='`head -1 '.DATAFILE.'`' #macro: Single quotes are important here to prevent expansion of backtics.
set title #TI
plot DATAFILE u 1:2 title columnhead(1)
Note that if your title isn't enclosed in double quotes in the datafile, you'll need to add
them so that the resulting set title command is valid. (You can either add them to the macro, or to the datafile)
Even if this is rather late and the OP's account doesn't exist anymore, I need to add an answer, because it is simply not true that you cannot extract a title from a datafile with gnuplot only.
You can run stats (check help stats) without actually being interested in statistics but just for extracting the title.
You limit the data to the line of interest via every (check help every).
This works for gnuplot 4.6.0 (March 2012).
For gnuplot>=4.6.0 you can set a character as datafile separator (check help datafile separator). Take a character which doesn't appear in the line with the title. For gnuplot>=4.6.0 you can set datafile separator "\t" or for gnuplot>=5.0.0 you can also set datafile separator "\n".
Data: SO10968529.dat
# This is a commented line
"Line2: This is a uncommented line in double quotes"
"Line3: my Title"
Line5: This is a title without quotation marks
"Line6: Another title"
# x y
1 5.0
2 3.0
3 4.0
4 2.0
# end of data
Script:
### read title from datafile
reset
FILE = "SO10968529.dat"
set multiplot layout 1,2
set datafile separator "\t"
stats FILE u (myTitle=strcol(1),0) every ::0:0:0:0 nooutput
set datafile separator whitespace
set title myTitle
plot FILE u 1:2 w lp pt 7 lc rgb "red"
set datafile separator "\t"
stats FILE u (myTitle=strcol(1),0) every ::0:1:0:1 nooutput
set datafile separator whitespace
set title myTitle
plot FILE u 1:2 w lp pt 7 lc rgb "blue"
unset multiplot
### end of script
Result:

Resources