LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   gnuplot, pull X data from file, specify Y data at cmd line? (https://www.linuxquestions.org/questions/programming-9/gnuplot-pull-x-data-from-file-specify-y-data-at-cmd-line-537571/)

hedpe 03-14-2007 08:54 PM

gnuplot, pull X data from file, specify Y data at cmd line?
 
Hey all,

I was wondering if its possible with gnuplot, for me to pull the X axis points from a file while plotting, but on the gnuplot command line specify Y for all points. Something like this:

Code:

plot "data/flood" Y 3 with linespoints title "degree_in"
that would get all of the X-axis data points from data/flood and use Y=3 for all of the points. Is this possible some how? You might say to simply add 3 to the file for all of the points, but I have different plots which will be using this same file for which I want the Y to be different. So I was hoping to be able to specify it on the cmd line

nmh+linuxquestions.o 03-14-2007 10:34 PM

I have seen no indications that this is possible, and so when I want to do something similar to this, I use python and have it do whatever processing I want, and then use gnuplot just for plotting.

alesz 03-15-2007 01:33 AM

I have had a similar/almost same problem many times. But in the end, i ended creating a file or a stream by sed, awk or any other program and then piping it to gnuplot, e.g. this one is from 2 days ago:

cat ../../input/gnuplot-att2d.in | sed -e "s*OUTPUT*atts_$FUN.eps*g" < gnuplot-att2d.in \
gnuplot

Here i was only changing the EPS output file name, but I am sure that you can understand my approach. Btw. if you perhaps need to concatenate columns within input file, use "paste" unix command.

nx5000 03-15-2007 05:27 AM

Quote:

Originally Posted by /tmp/data
1
2
5
10
20 bla
30:oh my god

./scrunch /tmp/data

scrunch script:
Code:

[[ "$1x" == "x" ]] && exit
tmp=`mktemp`
cat > $tmp << EOF
set terminal postscript eps colour
set output "scrunch.eps"
set yrange [0:5]
set xlabel "Data"
set ylabel "Flood"
plot \
"<awk -F'=| |:' '{print \$1\" \"3}' $1"  using 1:2 title "degree_in" with lines
EOF
gnuplot < $tmp
rm $tmp

Now you should have scrunch.eps in current directory

firstfire 03-15-2007 08:56 AM

Hello!

If I understand your problem right, following approach may be useful:
Code:

gnuplot> plot "<(awk '{print $4,$3}' u-log-10)" w l
Here I'm filter out 4th and 3rd columns from file u-log-10 (awk '{print $4, $3}' u-log-10), and then plot this data with style `lines'. As I understand, gnuplot syntax
Code:

plot "< source-of-data"
allows to plot the data from standard output of any program (e.g. `plot "<seq 10" ' will plot the straight line).

So you can plot all points from "data/flood" being projected to the line y=3 as follows:
Code:

plot "< awk '{print $1, 3}' data/flood" with linespoints title "degree_in"
P.S.: I suggest you to take a look at plotutils package. Using `graph' util from there may be much more handy in noninteractive mode.

julot 03-15-2007 11:32 PM

alternatives to gnuplot
 
have you tried PyX, or PyXPlot?


All times are GMT -5. The time now is 10:21 PM.