Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing data array to gnuplot via a pipe in c rather than a file

Right now I am passing a file to gnuplot via a a pipe in c, something like this:

 fprintf(gnuplotPipe, "plot \"data-file.dat\" using 1:2\n"); 

Is there any way that I don't have to write the data to a file and then pass it to gnuplot, so for example somehow pass an array or a stream to gnuplot, so I can skip the writing to a file process and then deleting the file? Any help would be appreciated.

like image 502
mihajlv Avatar asked Mar 01 '12 21:03

mihajlv


People also ask

How use gnuplot to plot data from a file?

To plot functions simply type: plot [function] at the gnuplot> prompt. Discrete data contained in a file can be displayed by specifying the name of the data file (enclosed in quotes) on the plot or splot command line. Data files should have the data arranged in columns of numbers.

What files can gnuplot open?

Gnuplot can read binary data files. However, adequate information about details of the file format must be given on the command line or extracted from the file itself for a supported binary filetype. In particular, there are two structures for binary files, a matrix binary format and a general binary format.

What is gnuplot C?

Gnuplot is a portable command-line driven graphing utility for Linux and other OS. C and Gnuplot can be used to plot complex functions. One can write the function in C and then write the values of the function at various values in a txt file, which can then be plotted using Gnuplot.

Does gnuplot support multiple Y axes on a single plot?

5.9 Does gnuplot support multiple y-axes on a single plot? Yes. 2D plots can have separate x axes at the bottom (x1) and top (x2), and separate y axes at the left (y1) and right (y2).


1 Answers

Sure you can do that. An example of a terminal command that plots two points connected by a line is:

echo "plot \"< echo -e '4 5\n 3 2'\" w lp pt 2" | gnuplot

If you want to have postscript output you can add the following:

echo "set terminal postscript; plot \"< echo -e '4 5\n 3 2'\" w lp pt 2" | gnuplot &> out.ps

If you now use system() or popen() (to catch the output stream) the rest should be straightforward.

Edit: There seems to exist some C(++) - Gnuplot interfaces. Check out this website which gives a great overview over C, C++, Python and Fortran wrappers. I'm not sure whether they are up to date and work with the latest Gnuplot versions but if not adapting shouldn't be that difficult.

like image 111
Azrael3000 Avatar answered Oct 02 '22 17:10

Azrael3000