【问题标题】:Gnuplot saving many imagesGnuplot 保存许多图像
【发布时间】:2023-04-10 20:14:02
【问题描述】:

我想将 gnuplot 操作的结果写入 png 文件,这会成功,但我需要生成大约 100 个 png 文件,在这里我遇到了问题,因为我收到“gnuplot 临时文件的最大数量为 27”的错误.当我使用方法 remove_tmpfiles() 时,所有图像都会正确生成,但其中大约 20-30 个无法打开。当我只保存推荐的 27 张图片时,不会出现此错误。

Gnuplot::set_GNUPlotPath( GNUPLOT_PATH );
Gnuplot *main_plot = new Gnuplot;    
main_plot->cmd("set terminal pngcairo\n");
for(int j=0; j<100;j++)
{   
 rysuj_wagi(j, main_plot);  
 if(j%25 == 0) main_plot->remove_tmpfiles(); 
} 


    void rysuj_wagi(int numer, Gnuplot * main_plot)
{
  std::ostringstream oss;
  oss <<"set output 'waga" << numer<<".png'";
  string output = oss.str();
  cout<<output;
  main_plot->cmd(output); 
  main_plot->set_grid(); 
  main_plot->set_xrange(-5,5);
  main_plot->set_yrange(-5,5);
  main_plot->set_style( "linespoints" );
  main_plot->set_pointsize( 1.0 );  
  vector<double> x, y;
  x.push_back(0); 
  y.push_back(0);
  x.push_back(punktyWagX[numer]);
  y.push_back(punktyWagY[numer]);
  main_plot->reset_plot();
  main_plot->plot_xy(x, y); 
}   

你碰巧知道出路吗?

【问题讨论】:

  • 哪些文件无法打开?尝试在函数rysuj_wagi 的末尾添加main_plot-&gt;cmd("set output");。只有在遇到新的set output 'filename' 时,Gnuplot 才会最终确定输出文件。也许这会干扰remove_tmpfiles()。为避免这种情况,发送set output(是的,没有文件名)可能会有所帮助。
  • 它总是没有为每 25 个图像创建大约最后 10 个图像。您的解决方案有效,但是当我删除 temp_files() 时,大约 100 个图像中的 4 个无法打开。我的想法是它删除 temp_file 太快了,所以我强迫它休眠一段时间 for(int j=0; jremove_tmpfiles(); } } 这也有效。感谢您的努力。

标签: c++ c png gnuplot


【解决方案1】:

您似乎正在使用此 API:http://jfi.uchicago.edu/~tcaswell/track_doc/classgnuplot_1_1Gnuplot.html

你有没有尝试过这样的事情:

main_plot->cmd("set terminal pngcairo\n");         
//some setting of YOUR_FILENAME
main_plot->cmd("set output 'YOUR_FILENAME'\n");
main_plot->cmd("replot\n");

希望您可以同时避免使用临时文件。

【讨论】:

    猜你喜欢
    • 2011-04-14
    • 1970-01-01
    • 2021-07-11
    • 2018-05-10
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    • 2015-11-04
    • 1970-01-01
    相关资源
    最近更新 更多