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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With