aneela
aneela

Reputation: 1619

Generating mutilple plots in one gnuplot window

I've got many files containing data and I want to plot all the data in a single gnuplot window. I'm using C. My current code is

gnuplotPipe = popen ("gnuplot -persistent", "w");
//loop starts for each file
system("gnuplot -p -e \"plot 'file_variable'""); // skipping some steps to generate variable file name
//end loop
fclose(gnuplotPipe);

It is generating graphs in individual windows. How to combine all of them in one?

Files format are like

2 0.000003
2 0.000002
2 0.000002

in file_2.txt

3 0.000001
3 0.000000
3 0.000001

in file_3.txt

.
.
.

in file_n.txt n is between 3 and 98

99 0.004800
99 0.004752
99 0.004716

in file_99.txt.

Any help would be appreciated.

Upvotes: 1

Views: 179

Answers (1)

Ayan
Ayan

Reputation: 817

Usually the plot command can take multiple file names at once as argument and plot their data in a single graph.

plot 'file_1', 'file_2', .... 'file_n'

So you can construct a sting containing all the file names and then pass it in the system() function.

It will be something like this.

char *arg = "gnuplot -p -e \"plot";
//Start a loop
//Generate your variable file name
strcat(arg, generated_filename);
//End loop
gnuplotPipe = popen ("gnuplot -persistent", "w");
system(arg);
fclose(gnuplotPipe);

Just make sure the generated file names are composed into a string like this- " 'filename',"

(A white space followed by a single quote, file name, single quote and finally a comma)

You can learn more about plotting multiple files in a single graph in the last example here in this site. You can also format your graph if you want as shown in the example there.

Upvotes: 2

Related Questions