代码之家  ›  专栏  ›  技术社区  ›  MysteryGuy

将参数传递给GNUPLOT配置文件

  •  0
  • MysteryGuy  · 技术社区  · 7 年前

    这是我的gnuplot配置文件:

    reset
    set terminal png
    set output "rp.png"
    set title textcolor rgb "red" "R/P"
    set yrange[0:110]
    set xrange[0:110]
    set xlabel "Rappel"
    set ylabel "Précision"
    set style data points
    plot "test.dat" using 2:1 with linespoints
    

    目前我只是在做这个

    FILE *gp;
     if(WIN32)
     {
       cout<<"Win 32"<<endl;
    
       gp=_popen("gnuplot", "w");
     }
     else
     {
       cout<<"pas win 32"<<endl;
       gp=popen("gnuplot", "w");
     }
     if(gp == NULL)
     {
       fprintf(stderr, "Oops, I can't find %s.");
       //exit(EXIT_FAILURE);
     }
     fprintf(gp, "load \"config\"\n");
     fflush(gp); 
     pclose(gp);
    

    先谢谢你

    2 回复  |  直到 7 年前
        1
  •  0
  •   kebs    7 年前

    类似这样的功能使您能够完全控制所需内容(抱歉,太快了,太脏了,只有Linux代码):

    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    
    int main()
    {
       std::ofstream f("myfile.plt");
       f << "#!/usr/local/bin/gnuplot\n";
       f << "reset\nset terminal pngcairo\n";
       //... the rest of what is needed
       std::string fn = "whatever.dat";
       f << "plot \"" << fn << "\" using 2:1 with linespoints\n";
       f.close();
       std::system( "chmod u+x myfile.plt" );
       std::system( "myfile.plt" );
    }
    

    (切换到 pngcairo 终端,产生的输出比 png ).

        2
  •  0
  •   ewcz    7 年前

    您可以只设置一个包含文件名的变量:

    fprintf(gp, "filename=\"%s\";load \"config\"\n", file_name);
    

    reset
    set terminal png
    set output "rp.png"
    set title textcolor rgb "red" "R/P"
    set yrange[0:110]
    set xrange[0:110]
    set xlabel "Rappel"
    set ylabel "Précision"
    set style data points
    plot filename using 2:1 with linespoints