gnuplot png unkown and pdf error - gnuplot

I have a shell script that performs some calculations and plot the results. I have used gnuplot for plotting the results. I'm facing two problems. I used to run the script on my cygwin and it's Okay. When I tried to run it on Ubuntu (Version 10.04-wubi-version), it couldn't recognize the png files (set terminal png unknown). I have tried to install (missing libraries that support "libgd2_2.0.36~rc1~dfsg" and update the libraries.... no luck !! then I have decided to use set terminal pdf instead since I found it supported :
here is my gnuplot version:
G N U P L O T
Version 4.4 patchlevel 0
last modified March 2010
System: Linux 2.6.35-32-generic
here is the output of terminal types:
latex LaTeX picture environment
mf Metafont plotting standard
mif Frame maker MIF 3.00 format
mp MetaPost plotting standard
nec_cp6 NEC printer CP6, Epson LQ-800 [monocrome color draft]
okidata OKIDATA 320/321 Standard
pbm Portable bitmap [small medium large] [monochrome gray color]
pcl5 HP Designjet 750C, HP Laserjet III/IV, etc. (many options)
-->pdf PDF (Portable Document File) file driver
postscript PostScript graphics, including EPSF embedded files (*.eps)
pslatex LaTeX picture environment with PostScript \specials
pstex plain TeX with PostScript \specials
Now, After I have modified the shell script to use pdf, I'm getting this error (Note: some of the pdf files are created ).
line 0: ';' expected
Again, I've added ';' to all of the lines.... and the error still appears.
Here is part of my shell script (that gives the error):
gnuplot << TOEND ;
set terminal pdf;
set output 'A.pdf';
set autoscale ;
#unset log
#unset label
set xtic auto ;
set ytic auto ;
set title "title";
set xlabel "x axis";
set ylabel "y axis";
######################################
#UPDATE: I have added double space to a void the error
######################################
plot "A1.tr" using 1:2 title "A" with lines 9, \
"A2.tr" using 1:2 title "B" with lines 11
the output (Note this part is not of the created pdf files):
line 0: invalid character \ --->pointing to 9, \
line 0: invalid command --->poiting to A2.tr
the rest of shell script produces the same error (Note: output is created)
......
......
######################################
#UPDATE: #psibar pointed that 'ls' missing
######################################
plot "results.tr" using 1:2 title "Results" with lines ls 9;
^
line 0: ';' expected---> pointing to 9 ;
After long searching, I think the problem has to do with version of UBUNTU and Gnuplot....I don't want to upgrade my version of ubuntu.....
After solving the errors. Any suggestions on how to get the "set terminal png" works on ubuntu 10.04 ??

To solve the problem I have added ls and double spaces after the 9, \.
The final answer would be :
gnuplot << TOEND ;
set terminal pdf;
set output 'A.pdf';
set autoscale ;
#unset log
#unset label
set xtic auto ;
set ytic auto ;
set title "title";
set xlabel "x axis";
set ylabel "y axis";
######################################
#UPDATE: I have added double space to a void the error
# and #psibar pointed that 'ls' was missing
######################################
plot "A1.tr" using 1:2 title "A" with lines ls 9, \
"A2.tr" using 1:2 title "B" with lines 11

Related

using gnuplot to read in - not output - a png image, or many, in one session - as an "overlay"

I want to read multiple png files - which themselves were created with gnuplot (terminal png) - in order to achieve an "overlay" - that is, a number of functions plotted together one on top of the other, with no background. This apparently could be done with gnuplot in one session.
I found this idea from the Linux Gazette article "Plotting the spirograph equations with 'gnuplot' ", from 2006 :
https://linuxgazette.net/133/luana.html
I am stuck on a number of error messages (vide infra) :
line 0: Bad data on line 1 of file [...]
line 0: warning: using default binary record/array structure
line 0: Too many using specs for this style
Looking for solutions, I read in the help pages ( http://gnuplot.info/docs_5.5/loc7742.html ) that gnuplot can read png images :
plot 'file.png' binary filetype=png
... and I have looked into using pngcairo instead of png itself. I am using eog to view the .png images. Here is sample code which generates the error above, and more if adjusted :
set size ratio -1
set nokey
set noxtics
set noytics
set noborder
set parametric
i2p = {0,1}*2*pi
set terminal png
t0 = 0
t1 = 1
#---------------------------------------------
# plot first function in the gnuplot session :
#---------------------------------------------
test01(t) = exp(i2p*(2*t))
set output "solve_png_problem_15nov22a.png"
plot [t=t0:t1] 1*real(test01(t)),1*imag(test01(t)) lc 1
#---------------------------------------------------
# plot second function in the same gnuplot session :
#---------------------------------------------------
test02(t) = + 3*1.0**20 * exp(i2p*(-3*t+20/200. )) + 3*1.0**19 * exp(i2p* (2*t+20/200.))
set output "solve_png_problem_15nov22b.png"
plot [t=t0:t1] 1*real(test02(t)),1*imag(test02(t)) lc 2
#------------------------------------------------------------
# last plotting to apparently "overlay" the two plots above :
#------------------------------------------------------------
set terminal png size 600,600
set output "solve_png_problem_15nov22_overlay.png"
set noparametric
plot "solve_png_problem_15nov22a.png", "solve_png_problem_15nov22b.png"
.... the reduced sample code is generated from the awk script supplement to the article - see it for detail :
https://linuxgazette.net/133/misc/luana/spirolang.awk.txt
The functions are nontrivial so they were kept in tact, as the associated settings might be causing the problem. The individual images look ok, so I think the problem is in the last plot command.
I read in the help pages that gnuplot can read png images :
plot 'file.png' binary filetype=png
... and also filetype=auto, and I have looked into using pngcairo instead of png itself, with no progress ; I have read the results of Google searches for the error messages. I have read the help pages on terminal, png, image, binary, and so on. I was expecting gnuplot to simply recognize the file was a png image that gnuplot itself generated, using the png terminal. What actually results is the error"Too many using specs for this style". For this, I have tried moving the position of the "binary filetype=png" in the code, which give the error "line 0: Bad data on line 1 of file [...]". I have also tried using programs outside gnuplot, such as montage and composite (ImageMagick).
gnuplot version 5.4 patchlevel 2
Ubuntu 22.04
post-answer update:
TL;DR : use svg terminal.
I saved a lot of grief by simply using the svg terminal. The original work must have been published before gnuplot got the svg terminal. I still need to work svg into the original script - but svg will make it a lot easier.
Try this in GNUPLOT.
gnuplot<<EOF
set terminal png medium size 600,600 background rgb "white"
set size ratio -1
set nokey
set noxtics
set noytics
set noborder
set parametric
i2p = {0,1}*2*pi
t0 = 0
t1 = 1
#---------------------------------------------
# plot first function in the gnuplot session :
#---------------------------------------------
test01(t) = exp(i2p*(2*t))
set output "solve_png_problem_15nov22a.png"
plot [t=t0:t1] 1*real(test01(t)),1*imag(test01(t)) lc 1
#---------------------------------------------------
# plot second function in the same gnuplot session :
#---------------------------------------------------
test02(t) = + 3*1.0**20 * exp(i2p*(-3*t+20/200. )) + 3*1.0**19 * exp(i2p* (2*t+20/200.))
set output "solve_png_problem_15nov22b.png"
plot [t=t0:t1] 1*real(test02(t)),1*imag(test02(t)) lc 2
#------------------------------------------------------------
# last plotting to "overlay" the two plots above :
#------------------------------------------------------------
set output "solve_png_problem_15nov22_overlay.png"
plot \
[t=t0:t1] 1*real(test01(t)),1*imag(test01(t)) lc 1, \
[t=t0:t1] 1*real(test02(t)),1*imag(test02(t)) lc 2
EOF
First Result:
Second Result:
Combined Result:

Creating a command with sprintf. Is this possible?

I want to plot some data. The data is in several files and the line it is in is not always the same. Therefore I used grep and some other commandline tools to extract the line I want. I read online, that it should be possible with gnuplot to print from a string or from the result of a commandline.
I work in linux.
set terminal pdfcairo enhanced font "Garamond,10" fontscale 1.0 size 9in,9in
set nogrid
set samples 1001
set border 31 linewidth .3
set output "access/accessTimeAcrossFreq.pdf"
set xlabel "freq"
set ylabel "Time [s]"
set key right top
set size square
set autoscale y
set termoption lw 2.5
volts = "0.8"
fins = "111 122 222"
freq = "0.5G 1G 1.5G 2G 2.5G 3G"
metrics = "read1bldeltav read0bldeltav read1senseChange read0senseChange read1latchChange read0latchChange sense1speed sense0speed write1CellFlip write0CellFLip write1CellSwing write0CellSwing write1BLSwing write0BLSwing powerpertime"
runTitle = "abetraryString"
filename(fin, f, volt) = sprintf("../%s_temp27_fin%s_freq%s_vdd%s/accessTimeVolLSA/result.txt", runTitle, fin, f, volt)
data(met, file) = system(sprintf("grep -n '%s' %s | cut -d: -f 2 | awk '{$1=$1};1'", met, file))
com(met, file) = sprintf("< grep -n '%s' %s | cut -d: -f 2 | awk '{$1=$1};1'", met, file)
do for [fin in fins] {
do for [v in volts] {
do for [met in metrics] {
set title sprintf("%s VLSA across Freq, fins %s, %sV, w/o she", met, fin, v)
plot for[i=1:words(freq)] com(met, filename(fin, word(freq, i), v)) using (i):2:xtic(word(freq, i)) notitle with points lc i
}
}
}
So I was wondering if a) I can have a function that returns a string that is a command that is then run by gnuplot
b) Where the error might come from:
line 32: warning: Skipping data file with no valid points
line 32: warning: Skipping data file with no valid points
line 32: warning: Skipping data file with no valid points
line 32: warning: Skipping data file with no valid points
line 32: warning: Skipping data file with no valid points
line 32: warning: Skipping data file with no valid points
line 32: x range is invalid
I thought, maybe I need a linebreak at the end of my one-liner of data. Or because gnuplot always thinks the first line is not data... I don't know.
Today I figured it out. I used prints in the for loop to see what the command returns. Before I posted the question I tried the command in a separate terminal with success. The problem was I just tested it with the first element of metrics. The prints revealed that I forgot the metrics need to be all lower case.
To conclude. Yes, you can put a string via a function together and gnuplot will then run it as I was expecting it. See the use of com(..) in the plot line.
Second. I think the xrange error usually points out that in a plot there are no data points and gnuplot does not like a xrange of 0. To figure this out I used prints. I did a quick search if there is a verbose mode but was not successful, so prints it is.
Maybe someone can take away something like I did.

Gnuplot only Plotting one Dot instead of all data

I am trying to plot time vs entropy of a data. When I run the script, it just produces a graph with one dot on y axis and no plot. Here is my script:
set terminal png
set output 'output.png'
set xdata time
set timefmt '"%Y-%m-%d %H:%M:%S"'
set format x '"%Y-%m-%d %H:%M:%S"'
set xrange ['"2008-01-01 00:00"':'"2008-03-20 00:00"']
set yrange [0.5:2.4]
set style data lines
set xlabel "Time"
set ylabel "Entropy"
plot "foobar-entropy.txt" using 1:2 w lp ls 4 lw 3
And here is the data:
"2008-01-01 02:13:38" 1.0
"2008-01-10 02:12:13" 1.5
"2008-01-20 02:11:55" 1.459
"2008-01-30 02:10:28" 1.811
"2008-02-10 02:09:44" 1.722
"2008-02-20 02:08:00" 1.65
"2008-02-28 02:07:00" 2.149
"2008-03-10 02:06:00" 2.18
"2008-03-20 02:04:00" 2.33
Any help would be appreciated.
Finally, found the mystery after #Christoph told about the line breaks. The issue was that the file had different line endings which gnuplot do not support.
When I opened the file with vi editor it appeared as follows:
"2008-01-01 02:13:38" 1.0^M
"2008-01-10 02:12:13" 1.5^M
"2008-01-20 02:13:55" 1.459^M
"2008-01-30 02:12:28" 1.811^M
"2008-02-10 02:12:44" 1.722^M
"2008-02-20 02:13:00" 1.65^M
"2008-02-28 02:13:00" 2.149^M
"2008-03-10 02:13:00" 2.18^M
"2008-03-20 02:13:00" 2.33^M
After running the command dos2unix on the file, it changed the old-style carriage-return characters to linefeeds and it works fine now.

How to fix ';' expected error in gnuplot

I am using ubuntu 14.04, gnuplot 4.6 patchlevel 4.
I have the following script, named Plot.script:
## GNUPLOT command file
set terminal postscript color
set style data lines
set noxzeroaxis
set noyzeroaxis
set key top spacing .8
set size ratio 0.821894871074622
set noxtics
set noytics
set title 'Combined DET Plot'
set ylabel 'Miss probability (in %)'
set xlabel 'False Alarm probability (in %)'
set grid
set pointsize 3
set ytics (\
'5' -1.6449, '10' -1.2816, '20' -0.8416, '40' -0.2533, '60' 0.2533, \
'80' 0.8416, '90' 1.2816, '95' 1.6449, '98' 2.0537)
set xtics (\
'.0001' -4.7534, '.001' -4.2649, '.004' -3.9444, '.01' -3.7190, '.02' -3.5401, \
'.05' -3.2905, '.1' -3.0902, '.2' -2.8782, '.5' -2.5758, '1' -2.3263, \
'2' -2.0537, '5' -1.6449, '10' -1.2816, '20' -0.8416, '40' -0.2533)
plot [-4.75343910607888:-0.253347103317183] [-1.64485362793551:2.05374890849825] \
-x title 'Random Performance' with lines 1,\
'tmp/score.det.sub00.dat.1' using 3:2 title 'Term Wtd. fake : ALL Data Max Val=0.267 Scr=0.436' with lines 2,\
'tmp/score.det.sub00.dat.2' using 6:5 notitle with points 2,\
'tmp/score.det.sub01.dat.1' using 3:2 title 'Term Wtd. fake: CTS Subset Max Val=0.267 Scr=0.436' with lines 3,\
'tmp/score.det.sub01.dat.2' using 6:5 notitle with points 3
Then I run gnuplot Plot.script | ps2pdf - .
I get the following error:
line 27: ';' expected
line 27 is the last row of the script:
'tmp/score.det.sub01.dat.2' using 6:5 notitle with points 3
I have searched from web and found this similar question but it doesn't seem to help. Does anyone know what the problem is?
In general it is very hard to debug such a long script, especially without having the test data to run exactly this script. You should start by cutting down your script line by line to track down in which line the error really appears. The whole plot command is treated as a single line, so if it says line 27, the error can also appear earlier.
I guess, that you have the wrong syntax for selecting line types. Using with lines 1 doesn't work, and the simple line
plot x with lines 1
already shows this error. You must use
plot x with lines linetype 1
Accordingly you must fix all other positions where you set a line type (or point type).
line 27: ';' expected
can mean there's a ',' missing in the plot statement. I couldn't find it myself in your code. May be you need to delete blanks before "Scr="
But I had a similar problem.

How to print input file next to graph in gnuplot?

Is it possible with gnuplot to print the data that I plotted next to the graph?
If I have a text file input.txt:
#x y
1 2
2 5
3 6
4 7
And I do plot 'input.txt' I'd like to have it plotted as usual and next to the plot I'd like to have the table printed. Is this possible?
Note: I'm on Windows and I'd like to format the output.
A bit late, but the OP asked for Windows... so, in short:
data = system('type yourfile.dat') # Windows
In Windows, if you give a path, you need to pay attentention about \, spaces and doublequotes ".
Data: SO22225051.dat
#x y
1 2
2 5
3 6
4 7
Script:
Solution working for both Linux and Windows. Version 1 for gnuplot>=5.2.0, Version 2 for gnuplot>=4.6.0.
### place data as table/text in graph
reset
FILE = 'SO22225051.dat'
set rmargin 15
set label 1 at screen 0.9,0.7 font "Courier New,12"
# Version 1: Windows & Linux using system() command;
# GPVAL_SYSNAME only available for gnuplot>=5.2.0
getData(f) = GPVAL_SYSNAME[1:7] eq "Windows" ? \
system(sprintf('type "%s"',f)) : \
system(sprintf('cat "%s"',f)) # Linux/MacOS
Data = getData(FILE)
set label 1 Data
plot FILE u 1:2 w lp pt 7 lc rgb "red"
pause -1
# Version 2: gnuplot-only, platform-independent, working at least with gnuplot>=4.6.0
Data = ''
set datafile commentschar ''
set datafile separator "\t"
stats FILE u (Data=Data.strcol(1)."\n") nooutput
set datafile commentschar # restore default
set datafile separator # restore default
set label 1 Data
plot FILE u 1:2 w lp pt 7 lc rgb "red"
### end of script
Result:
The only difference between version 1 and 2 is that in version 2 gnuplot will remove leading spaces for each data line.
Sure you can. The simplest way to do this in gnuplot is read in the file by calling an external command (cat on *nix, not sure on Windows) and storing the output as a variable, then setting a label on the graph. Here is how I do it:
set rmargin 8
datas = system('cat data.dat')
print datas
set label datas at graph 1.1,0.7
plot 'data.dat' notitle
This puts the data file off to the side, in place of a key.

Resources