我有很多包含数据的文件,我想在一个 gnuplot 窗口中绘制所有数据。我正在使用 C。我当前的代码是
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);
它在各个窗口中生成图表。如何将它们合而为一?
文件格式如下
2 0.000003
2 0.000002
2 0.000002
在 file_2.txt
3 0.000001
3 0.000000
3 0.000001
在 file_3.txt
.
.
.
在file_n.txt
中n在3到98之间
99 0.004800
99 0.004752
99 0.004716
在 file_99.txt
中。
如有任何帮助,我们将不胜感激。
最佳答案
通常 plot
命令可以一次将多个文件名作为参数并将它们的数据绘制在一个图形中。
plot 'file_1', 'file_2', .... 'file_n'
因此您可以构造一个包含所有文件名的字符串,然后将其传递给 system()
函数。
会是这样的。
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);
只要确保生成的文件名组成这样的字符串- "'filename',"
(一个空格后跟一个单引号、文件名、单引号和最后一个逗号)
您可以在本 site 的最后一个示例中了解有关在单个图中绘制多个文件的更多信息.如果需要,您还可以设置图形格式,如此处的示例所示。
关于c - 在一个 gnuplot 窗口中生成多个图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29315424/