gnuplot frequency histogram in shell with only one column of information - shell

I want to make gnuplot with shell, i have similar code to do the whork, but i need to use only 1 column of integers to make frequency histogram.
this code puts out histogram that shows x axis every line and y axis its value, but i want to make frequency histogram for e.g. every 10 on x axis
code:
#!/bin/sh
#launch make_graphs $input $output_histogram.png $output_scatterplot.png $output_stats.txt
input=$1
output_h=$2
output_s=$3
output_stats=$4
gnuplot -persist <<-EOFMarker
set terminal png transparent truecolor
set output "$output_h"
set style data histogram
set style histogram cluster gap 50.0
set style fill solid border -1
set border lc rgb "red"
set xtics textcolor rgb "red"
set ytics textcolor rgb "red"
set key textcolor rgb "red"
set xlabel "sizes"
set ylabel "frequencies"
set boxwidth 3.0
plot "$input" using 1:xtic(2) title "seqlen frequences" ######### I need to change this line
set output "$output_s"
set xlabel "sizes"
set ylabel "frequences"
plot "$input" smooth csplines title "seqlen frquences"
set print "$output_stats"
stats "$input"
stats "$input"
#print "mean: ", STATS_sumxy/STATS_sum
#print "standart deviation: ", STATS_stddev
EOFMarker
input file egzample
12
278
99
9
219
219
164
185
164
438
438
438
438
185
164
286
286
12
12
10
10
35
35
6
6
6

Related

"invalid expression" running gnuplot in bash script

I am running this program SCRIPT.sh,
#!/bin/bash
FFT_FILE="$(find . -type f -iname "HR*.fft")"
FFT_FILE1=$FFT_FILE".GNUPLOT"
od -f -v -w8 $FFT_FILE > $FFT_FILE1
gnuplot -persist <<-EOFMarker
reset
set term postscript enh
set out 'FFT_1.ps'
set xlabel 'Frequency (Hz)'
set key box
filename="$FFT_FILE1"
stats filename nooutput
max_row = STATS_records
plot [(1000.0/4880.0):(1000.0/59.0)] filename u ($0/(max_row*81.92e-6)):(sqrt(($2*$2)+($3*$3))) w l lw 3 title "FFT"
reset
EOFMarker
but the output comes as
gnuplot> plot [(1000.0/4880.0):(1000.0/59.0)] filename u (./SCRIPT.sh/(max_row*81.92e-6)):(sqrt((*)+(*))) w l lw 3 title "FFT"
^
line 0: invalid expression
May I request for detailed explanation and help regarding this situation?
The "HR*.fft" file contains the results of Fast Fourier Transform from PRESTO in binary.

GNUPLOT error: When using arithmetic operation on one column of dat file in bash shell

#!/bin/bash
gnuplot -persist <<-EOFMarker
reset
set terminal svg enhanced size 500,500
set output 'plot.svg'
set autoscale # scale axes automatically
unset log # remove any log-scaling
unset label # remove any previous labels
set xtic auto # set xtics automatically
set ytic auto # set ytics automatically
set ylabel "Loading (mmol/gm)"
set xlabel "Pressure (kPa)"
set key left top
set key autotitle columnhead
set grid
plot "all_isotherm_15.dat" using (($2)/100000):3 title 'Simulation273K' with linespoints , \
"all_isotherm_15.dat" using (($2)/100000):5 title 'Simulation298K' with linespoints
EOFMarker
I am getting below error
gnuplot> plot "all_isotherm_15.dat" using (/100000):3 title 'Simulation273K' with linespoints , "all_isotherm_15" using (/100000):5 title 'Simulation298K' with linespoints
^
line 0: invalid expression
You get the $2 interpreted by bash as strings. As they are not defined, they get replaced by nothing.
Why not directly use gnuplot as the interpreter of the shell script, i.e., start the file as
#!/usr/bin/gnuplot -persist
reset
...

shell script of gnuplot: about various input files in a single graph for compare the lines

I am trying to plot a graph and save it as file using gnuplot. I have various text files. The number of text files is not sure. Each text file contains two columns. The text file is about linear absorption spectrum. The first column is the frequency and the second is the intensity. I want to compare the difference between the spectra by plot them in a single graph for all the files. I am using this script to do that.
#!/bin/bash
# plot linear absorption spectrum (las)
# Usage:
# ./lasplot.sh a.ods b.ods c.ods ..
j=1
for i in $*
do
echo "Normalization $i"
maxle=`cat $i|tr -s "," " "|awk 'BEGIN{max=0} {if($2>max) max=$2}END{print max}'`
echo " The max value is $maxle"
max[$j]=$maxle
filename[$j]=$i
((j=$j + 1))
done
num=$#
echo ${filename[*]}
echo $num
read -p "Please select set data range (1) or auto set(2): " setrange
case $setrange in
1)
read -p "set min x range: " minx
read -p "set max x range: " maxx
;;
esac
# call gnuplot to plot the 1D map
gnuplot << EOF
set datafile separator ","
set title 'Linear Absorption Spectra'
set xlabel '{/Symbol w} (cm^{-1})'
set ylabel 'Intensity (a.u.)'
#set data range
if (${setrange}==1){
set xrange [$minx:$maxx]
set yrange [0:1.1]
} else {
#set xrange [0:50]
#set yrange [0:50]
}
set size 1,1
set key right top
plot "${filename[1]}" using 1:(column(2)/${max[1]}) with lines linewidth 2 ,\
"${filename[2]}" using 1:(column(2)/${max[2]}) with points pointtype 21
pause mouse keypress "Type a letter"
set term pdfcairo font "arial,12"
set term pdfcairo enh
set term pdfcairo size 6,5
set output "las.pdf"
plot "${filename[1]}" using 1:(column(2)/${max[1]}) with lines linewidth 2 ,\
"${filename[2]}" using 1:(column(2)/${max[2]}) with points pointtype 21
EOF
My script can only plot two text files? How can change it to plot multiple input files?
you could prepare the plot command in your script before invoking gnuplot, store it into a variable and then reuse it in the gnuplot input (also avoiding thus repetition):
plotCmd="plot"
for((i=1;i<=${num};i++))
do
if [ $i -eq 1 ]; then
join=" "
else
join=", "
fi
plotCmd="${plotCmd}${join}\"${filename[$i]}\" using 1:2 with lines"
done
and then:
gnuplot << EOF
... some other stuff ...
${plotCmd}
EOF

Shell script for ploting multiple graph using gnuplot

I am trying to analyze multiple tcp congestion control algorithm and for that trying to plot multiple graph but i am not able to make one comparative graph.
This is my script code:
gnuplot -persist <<"EOF"
set xlabel "time (seconds)"
set ylabel "Segments (cwnd, ssthresh)"
plot "./cubic.out" using 1:7 title "snd_cwnd cubic", \
"./cubic.out" using 1:($8>=2147483647 ? 0 : $8) title "snd_ssthresh cubic",/
"./reno.out" using 1:7 title "snd_cwnd reno", \
"./reno.out" using 1:($8>=2147483647 ? 0 : $8) title "snd_ssthresh reno"
,/
EOF
But this script divides graph into two sub-section( both are not originating at origin)
Thanks
Following Miguel advice, here is what you should try (remember to have EOF starting the line, any space before it would make it irrelevant):
gnuplot -persist <<"EOF"
set xlabel "time (seconds)"
set ylabel "Segments (cwnd, ssthresh)"
plot "./cubic.out" using 1:7 title "snd_cwnd cubic", \
"./cubic.out" using 1:($8>=2147483647 ? 0 : $8) title "snd_ssthresh cubic", \
"./reno.out" using 1:7 title "snd_cwnd reno", \
"./reno.out" using 1:($8>=2147483647 ? 0 : $8) title "snd_ssthresh reno" , \
EOF

Plotting a single value with gnuplot?

I have the following csv file:
timestamp,unit,maximum,average
Thu Feb 05 14:54:00 GMT 2015,Percent,13.0,4.503333333333333
When I run the following bash script on it:
#!/bin/bash
graph_results() {
input=cpu-samples.csv
output=cpu-samples.png
gnuplot <<- eor
set terminal png
set output '${output}'
set style data linespoints
set xdata time
set timefmt '%b %d %H:%M:%S GMT %Y'
set format x '%b %d %Y %H:%M'
set datafile separator ","
set xlabel "timestamp"
set ylabel "percent"
set xtics rotate
plot '< tail -n +2 ${input} | cut -f 1 --complement -d" "' using 1:3 title 'Maximum', '' using 1:4 title 'Average'
eor
}
graph_results
I get the following error:
bash-4.1$ ./run_gnuplot
Could not find/open font when opening font "arial", using internal non-scalable font
Warning: empty x range [4.76463e+08:4.76463e+08], adjusting to [4.71699e+08:4.81228e+08]
And the resulting graph has the correct datapoint and timestamp on it, but the graph is filled out with incorrect date values for the x axis.
It works fine when the csv file has more than one value in it, but doesn't when there is only one value. I realize the error message is because with one value, the start and end range for the x axis is the same (as noted here http://gnuplot.10905.n7.nabble.com/empty-x-range-td1650.html).
I know I can set a range with the following:
set xrange
But unsure how I could use in in my case, since I'm using a custom date format, and I don't know what the start and end dates should be, since the data generated is dynamic?
When using a custom timefmt, the xrange must also be specified using this format:
set xrange ["Feb 04 00:00:00 GMT 2015":"Feb 09 00:00:00 GMT 2015"]
Or you can integers, i.e.a timestamp to set the xrange. With version 5.0 the line below is equivalent to the string settings above:
set xrange [1423008000:1423440000]
Note, that until version 4.6 gnuplot uses the first january 2000 as time reference for its timestamps, and only since 5.0 the standard Unix timestamp. So until 4.6, the equivalent command to the string settings in the first line would be
set xrange [476323200:476755200]

Resources