title: Gnuplot - Update graph each second
body: <p>I want to draw a graph that changes each second. I use below code, it changes the graph periodically. But each iteration doesn't keep previous iteration's points. How can I do it?
  There is only one points each second. But I want to draw the graph with history datas.</p>
  
  <pre><code>FILE *pipe = popen("gnuplot -persist", "w");
  
  // set axis ranges
  fprintf(pipe,"set xrange [0:11]\n");
  fprintf(pipe,"set yrange [0:11]\n");
  
  int b = 5;int a;
  for (a=0;a&lt;11;a++) // 10 plots
  {
      fprintf(pipe,"plot '-' using 1:2 \n");  // so I want the first column to be x values, second column to be y
      // 1 datapoints per plot
      fprintf(pipe, "%d %d \n",a,b);  // passing x,y data pairs one at a time to gnuplot
  
      fprintf(pipe,"e \n");    // finally, e
      fflush(pipe);   // flush the pipe to update the plot
      usleep(1000000);// wait a second before updating again
  }
  
  //  close the pipe
  fclose(pipe);
  </code></pre>