I have a database file that looks like:
aaa bb ccc 2 3.34534 kkk 3 4.5099 34%
rr wie fff 4 4.59050 asd 6 5.0983 1.345%
I need to plot a range starting at the 'y' value of the 5th column (i.e. 3.34534) up to the value on the 8th column. Or lets say, a y=3.34534 line with line width of 4.5099-3.34534 for the first line. Or, some sort of filled curve between y=3.34534 and y=4.5099 for the first line. This has to be done for all lines a filled curve between the value on the 5th column and the 8th column. The question is, how to access those values and input them into gnuplot. A shell script maybe? (So far I have managed to save the values to an array x() and y(): for value in column5 first line accessed by ${x[0]} and the one in the 8th column to ${y[0]}, the question now would be how to input values from the array into the gnuplot syntax via EOF>>). Any help appreciated.
If you want to have everything together in the bash script, you can first define a variable, which contains all gnuplot code (see e.g. BASH: Keeping formatting but substituting variables):
read -r -d '' GNUPLOT_SCRIPT <<EOF
set xrange [0:1];
plot x
EOF
Note, that with that construct every line of the gnuplot code must be terminated with a ;.
For the plotting I would use the boxxyerrorbars plotting style, which plots boxes at a point with a given width and height. In the gnuplot using statement, the first and second value are the x and y values of the box center, the third and fourth values give the half box width and height.
You didn't say anything about the x-values, so I chose the xrange to be from 0 to 1.
Assuming, that you "database" is in a string, the bash script looks like the following:
#!/bin/bash
database="aaa bb ccc 2 3.34534 kkk 3 4.5099 34%
rr wie fff 4 4.59050 asd 6 5.0983 1.345%"
read -r -d '' GNUPLOT_SCRIPT <<EOF
set xrange[0:1];
set style fill solid 1.0;
set style data boxxyerrorbars;
unset key;
plot '-' using (0.5):(0.5*(column(5)+column(8))):(0.5):(abs(0.5*(column(5) - column(8))))
EOF
echo "$database" | gnuplot -persist -e "$GNUPLOT_SCRIPT"
If you want to save the plot in a file, you don't need the -persist option.
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