Making C code plot a graph automatically

后端 未结 5 2145
离开以前
离开以前 2020-11-30 00:49

I have written a program which writes a list of data to a \'.dat\' file with the intention of then plotting it separately using gnuplot. Is there a way of making my code pl

5条回答
  •  忘掉有多难
    2020-11-30 01:28

    I've adapted the accepted answer to plot a float array while avoiding the use of a temporary file. In it, float* data_ is the array and size_t size_ its size. Hopefully it is helpful for someone!

    Cheers,
    Andres

    void plot(const char* name="FloatSignal"){
      // open persistent gnuplot window
      FILE* gnuplot_pipe = popen ("gnuplot -persistent", "w");
      // basic settings
      fprintf(gnuplot_pipe, "set title '%s'\n", name);
      // fill it with data
      fprintf(gnuplot_pipe, "plot '-'\n");
      for(size_t i=0; i

提交回复
热议问题