The error msg:
multiplot> plot file1 u ($1/100):2 t "" w lp
line 0: all points y value undefined!
is listed when the script (below) is executed. What am I doing wrong?
#!/bin/bash
cat > x.dat <<- "EOF"
100 1
200 2
300 3
EOF
cat | gnuplot <<- "EOF"
file1="x.dat"
set multiplot layout 2,1
stats file1 u 1:2 name "A"
set xrange [A_min_x:A_max_x]
plot file1 u 1:2 t"" w lp
plot file1 u ($1/100):2 t "" w lp
unset multiplot
EOF
Your command set xrange [A_min_x:A_max_x] set the xrange to [100:300]. But the second plot command divides x by 100, so all the points would have x<100 and hence are out of range. Try set xrange [0:A_max_x] instead.
Related
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 ",\".
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"
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
I am encountering strange behavior on my gnuplot script. The objective of this script is to read in a file and plot a specific set of lines (3 consecutive lines based on a given start point in the file) using the very first line of the file as the series headers.
While the plot works conceptually, I am encountering a large insert into the image on the left side, as if an empty line is read and plotted as 0 (with no header)
Input File:
Level,Filter,Type,Set1,Set2,Set3
Level1,Filter1,Type1,112,186,90
Level1,Filter1,Type2,233,335,159
Level1,Filter1,Type3,224,332,157
Code:
set terminal postscript color
set output '| epstopdf --filter --outfile=output.pdf'
set boxwidth 0.5
set style fill solid
set style data histograms
set datafile separator ","
LINE1 = 1 + 3 * COUNT
LINE2 = LINE1 + 1
LINE3 = LINE1 + 2
plot '../test.csv' \
u ( ( int($0) == LINE1 || int($0) == LINE2 || int($0) == LINE3)? $4 : 1/0) ti col,'' \
u ( ( int($0) == LINE1 || int($0) == LINE2 || int($0) == LINE3)? $5 : 1/0) ti col,'' \
u ( ( int($0) == LINE1 || int($0) == LINE2 || int($0) == LINE3)? $6 : 1/0) ti col
Command Line Call
>gnuplot -e "COUNT=0" test.plot
How can I get rid of the empty fields that lead to the right shift?
My gnuplot version is 4.6.
Since you're already using pipes and unix-ish tools, I would use sed here as well:
set term post color
set output 'foo.ps'
set style data histograms
set style histogram clustered
set datafile separator ","
set boxwidth 0.5
set style fill solid
SED_CMD = sprintf('< sed -n -e 1p -e %d,%dp test.csv',COUNT*3+2,COUNT*3+4)
plot for [COL=4:6] SED_CMD u COL ti col
I've simplified a lot of things while I was trying to figure out what your script was doing -- I used plot iteration (introduced in gnuplot 4.3). Originally I had thought that plot '...' every ... would work, but histograms seem to choke on every and I don't (yet!) understand why.
Here's an explanation of the sed command:
-e 1p #print first line in file
-e %d,%dp #print n'th line through m'th line (inclusive) where n=COUNT*3+2 and m=COUNT*3+4
If you're worried about shell injection, this seems to be safe as well:
gnuplot -e 'COUNT=";echo hi"' -persist test.gp
"test.gp", line 10: Non-numeric string found where a numeric expression was expected
Gnuplot will only write numbers to your command string.
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: