I have a text file, each line of which contains two blank separated fields: x and y.
1 0 10 29 5 2
Now I would like to see the graph of y = f(x), where x and y are taken from the file.
I would prefer a curses picture in a terminal but it can be a picture in any graphics format as well.
What is the easiest way to do it in bash?
Here’s a very funny possibility. The thing I’m going to show you here is probably not what you’re looking for, it’s probably not optimized, it’s probably a whole bunch of junk, but it’s really funny. (I’m not expecting any upvotes for it).
This script more or less plots a
*at each point the coordinates of which are given in a file (given as first argument of the script). It computes the number of rows and columns of your terminal (using the commandstty, if you happen to have it installed, it’s good, otherwise, well, it’s not going to work).Call the script
plot_file_in_terminal(or maybe a shorter name).You can try it, it’s very funny, with a Mandelbrot set: the following script generates an M-set (you can give the number of pixels for the x and y coordinates as input, well, figure out a few things by yourself):
Name it
genMandelbrotand use it as./genMandelbrot > Msetor./genMandelbrot 100 50 > Msetif your terminal is more or less 100×50. Then:Nice, eh?
If you want a sine function (say from 0 to 2*pi):
Then call:
Outputs
Mandelbrot Set (in 80×24)
Sine (in 80×24)
In your OP you mentionned “the easiest way of doing”… well, you can notice, this solution it’s not exactly a one-liner.
Edits.
xmin!=xmaxandymin!=ymaxso as to not divide by 0xmin,xmax,ymin,ymaxin the samebcinstance.tputanymore, it was retarded and too slow! Instead, build an array of points (each field contains a space or*).Todos.