gnuplot, pull X data from file, specify Y data at cmd line?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.